0

В общем, вот такой интерфейс: введите сюда описание изображения

Просто таблица из 3-ех столбцов.

Я пытался найти, как задать расстояние между строками и столбцами таблицы, но не нашел.

Можно ли это как-то сделать через стили, чтобы руками у каждого элемента не прописывать?

Я нашел вот такое решение, но что-то оно у меня не работает...

    <Style TargetType="Border" >
        <Setter Property="Padding" Value="10,10,10,10" />
    </Style>

Пример разметки, но я тут уже руками успел прописать везде Margin...

<Window x:Class="DictionaryCreator.UI.Windows.SourceConfigurationWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DictionaryCreator.UI.Windows"
        mc:Ignorable="d"
        Title="Конфигурация источника" Height="420" Width="800">
    <Grid>
        <Grid.Resources >
            <Style TargetType="Border" >
                <Setter Property="Margin" Value="500" />
            </Style>
            <Style TargetType="Image" >
                <Setter Property="Height" Value="30" />
                <Setter Property="Width" Value="30" />
            </Style>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" ></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
    &lt;Label Margin=&quot;5&quot; Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Тип базы данных&lt;/Label&gt;
    &lt;ComboBox Margin=&quot;5&quot;  Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot; ItemsSource=&quot;{Binding Path=DbKinds}&quot; DisplayMemberPath=&quot;Name&quot; SelectedValue=&quot;{Binding Path=SelectedDbKind}&quot;&gt;&lt;/ComboBox&gt;
    &lt;Label Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Margin=&quot;5&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Сервер (MSSQL) или путь к файлу (MS ACCESS)&lt;/Label&gt;
    &lt;TextBox Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Margin=&quot;5&quot; Text=&quot;{Binding Path=FilePathOrServerName,UpdateSourceTrigger=PropertyChanged}&quot;&gt;&lt;/TextBox&gt;
    &lt;Label Grid.Row=&quot;2&quot; Grid.Column=&quot;0&quot; Margin=&quot;5&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Название базы данных&lt;/Label&gt;
    &lt;TextBox Grid.Row=&quot;2&quot; Grid.Column=&quot;1&quot; Margin=&quot;5&quot; IsEnabled=&quot;{Binding Path=DbNameEnable}&quot; Text=&quot;{Binding Path=DbName,UpdateSourceTrigger=PropertyChanged}&quot;&gt;&lt;/TextBox&gt;
    &lt;Label Grid.Row=&quot;3&quot; Margin=&quot;5&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Название таблицы&lt;/Label&gt;
    &lt;Grid Grid.Row=&quot;3&quot; Grid.Column=&quot;1&quot; Margin=&quot;5&quot;&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
            &lt;ColumnDefinition Width=&quot;Auto&quot;&gt;&lt;/ColumnDefinition&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;ComboBox Grid.Column=&quot;0&quot; DockPanel.Dock=&quot;Left&quot; MinWidth=&quot;300&quot; ItemsSource=&quot;{Binding Path=TableDescriptions}&quot; SelectedValue=&quot;{Binding Path=SelectedTableDescription}&quot;&gt;
            &lt;ComboBox.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;TextBlock&gt;
                        &lt;Run Text=&quot;{Binding Schema}&quot; /&gt;
                        &lt;Run Text=&quot;.&quot; /&gt;
                        &lt;Run Text=&quot;{Binding TableName}&quot; /&gt;
                    &lt;/TextBlock&gt;
                &lt;/DataTemplate&gt;
            &lt;/ComboBox.ItemTemplate&gt;
        &lt;/ComboBox&gt;
    &lt;/Grid&gt;
    &lt;Button Grid.Row=&quot;3&quot; Grid.Column=&quot;2&quot; Margin=&quot;5&quot; DockPanel.Dock=&quot;Right&quot; Command=&quot;{Binding Path=RefreshTablesCommand}&quot; &gt;
        &lt;Image Width=&quot;30&quot; Height=&quot;20&quot; Source=&quot;../Icons/Refresh.png&quot;/&gt;
        &lt;Button.ToolTip&gt;
            Обновить
        &lt;/Button.ToolTip&gt;
    &lt;/Button&gt;

    &lt;Label Grid.Row=&quot;4&quot; HorizontalContentAlignment=&quot;Right&quot; Margin=&quot;5&quot;&gt;Ключ таблицы (целое число)&lt;/Label&gt;
    &lt;ComboBox Grid.Row=&quot;4&quot; Grid.Column=&quot;1&quot; Margin=&quot;5&quot; ItemsSource=&quot;{Binding Path=ColumnDescriptions}&quot; DisplayMemberPath=&quot;ColumnName&quot; SelectedValue=&quot;{Binding Path=SelectedKeyColumnDescription}&quot;&gt;&lt;/ComboBox&gt;
    &lt;Label Grid.Row=&quot;5&quot; Margin=&quot;5&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Поле нормализуемого значения&lt;/Label&gt;
    &lt;ComboBox Grid.Row=&quot;5&quot; Margin=&quot;5&quot; Grid.Column=&quot;1&quot; ItemsSource=&quot;{Binding Path=ColumnDescriptions}&quot; DisplayMemberPath=&quot;ColumnName&quot; SelectedValue=&quot;{Binding Path=SelectedValueColumnDescription}&quot;&gt;&lt;/ComboBox&gt;
    &lt;Label Grid.Row=&quot;6&quot; Margin=&quot;5&quot; HorizontalContentAlignment=&quot;Right&quot;&gt;Идентификатор привязки к справочнику&lt;/Label&gt;
    &lt;ComboBox Grid.Row=&quot;6&quot; Margin=&quot;5&quot; Grid.Column=&quot;1&quot; ItemsSource=&quot;{Binding Path=ColumnDescriptions}&quot; DisplayMemberPath=&quot;ColumnName&quot; SelectedValue=&quot;{Binding Path=SelectedDictKeyColumnDescription}&quot;&gt;&lt;/ComboBox&gt;

    &lt;WrapPanel Grid.Row=&quot;7&quot;  Grid.ColumnSpan=&quot;3&quot; HorizontalAlignment=&quot;Center&quot; Margin=&quot;0 30 0 0&quot;&gt;
        &lt;Button Margin=&quot;0 0 25 0&quot; 
                Command=&quot;{Binding Path=SaveCommand}&quot;&gt;
            &lt;Button.Content&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Stretch&quot;&gt;
                    &lt;Image Margin=&quot;5 0 0 0&quot; Source=&quot;../Icons/Save.png&quot;/&gt;
                    &lt;Label&gt;Сохранить&lt;/Label&gt;
                &lt;/StackPanel&gt;
            &lt;/Button.Content&gt;
        &lt;/Button&gt;
        &lt;Button  Margin=&quot;0 0 25 0&quot; 
                Command=&quot;{Binding Path=CancelCommand}&quot;&gt;
            &lt;Button.Content&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Stretch&quot;&gt;
                    &lt;Image Margin=&quot;5 0 0 0&quot;  Source=&quot;../Icons/Cancel.png&quot;/&gt;
                    &lt;Label&gt;Отменить&lt;/Label&gt;
                &lt;/StackPanel&gt;
            &lt;/Button.Content&gt;
        &lt;/Button&gt;

    &lt;/WrapPanel&gt;

&lt;/Grid&gt;

</Window>

iluxa1810
  • 24,899
  • <Setter Property="Margin" Value="5" /> или <Setter Property="Margin" Value="5,5,5,5" />, что в принципе одно и то же. – aepot Mar 31 '21 at 11:42
  • @aepot так тоже пробовал, но не работает почему-то =(( – iluxa1810 Mar 31 '21 at 11:50
  • У меня работает. Но без разметки не понять. https://ru.stackoverflow.com/a/1256729/373567 вот я предлагал вам разметку, вы правда никак не отреагировали, и я удалил ответ, плюс на меня напал там EvgeniyZ и начал гнобить за то что я показываю практики а не прямо отвечаю на вопрос. – aepot Mar 31 '21 at 11:51
  • @aepot разметку я добавил – iluxa1810 Mar 31 '21 at 12:35
  • Не могу найти в разметке <Border>, к которому вы пытаетесь применить стиль. – aepot Mar 31 '21 at 12:37
  • @aepot Т.е каждый элемент я должен в Border бернуть? Эх, а я думал, что все автоматом как-то сделается) – iluxa1810 Apr 01 '21 at 07:07
  • Ну в border не обязательно оборачивать (так даже длиннее получится), можно просто прописать стиль для всех элементов с Margin. С помощью наследования стилей это можно будет чуть-чуть сократить. По сути вам нужны стили для Label, ComboBox, TextBox... – Андрей NOP Apr 02 '21 at 04:15
  • Ещё один вариант, если у вас много где такие гриды нужны — написать свою панель, которая будет делать отступы между ячейками самостоятельно – Андрей NOP Apr 02 '21 at 04:17

0 Answers0