AndyD273
AndyD273

Reputation: 7279

Padding on a Datagrid Row

I have a WPF Datagrid with a Text Column, two Template Columns, and two Checkbox Columns.
The template columns are center aligned vertically (equal padding top and bottom), the text column has a little padding on top, but a lot on the bottom, and the checkboxes only have about 1 pixel padding on top.

I'd like to center vertical align all of them, but I don't want to have to make a template column to hold the check boxes and text box.

What's the proper way to do this?

Edit: XAML

        <DataGrid AutoGenerateColumns="False" Name="dgROList" ItemsSource="{Binding ElementName=MainWindow, Path=cROInfo}" CanUserDeleteRows="True" CanUserReorderColumns="False" GridLinesVisibility="Horizontal" Margin="0,0,0,0" Grid.ColumnSpan="2" AlternatingRowBackground="#FFFFE776">
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Name="mnuDelete" Header="Delete" />
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTextColumn Header="RO Number" Width="Auto" Binding="{Binding RONum}" />
                <DataGridTemplateColumn x:Name="roDetails" Header="RO Details" Width="*">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ItemsControl Name="LineDetails" ItemsSource="{Binding LineInfo}" Width="Auto" Grid.IsSharedSizeScope="True">
                                <ItemsControl.Template>
                                    <ControlTemplate TargetType="ItemsControl">
                                        <ItemsPresenter />
                                    </ControlTemplate>
                                </ItemsControl.Template>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="20" />
                                                <ColumnDefinition Width="Auto" SharedSizeGroup="DetailCol"/>
                                                <ColumnDefinition Width="50" />
                                                <ColumnDefinition Width="150*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Content="{Binding Line}" Grid.Column="0" />
                                            <Label Content="{Binding Status}" Grid.Column="1" />
                                            <Label Content="{Binding AmountPaid}" Grid.Column="2" />
                                            <Label Content="{Binding SDate}" Grid.Column="3" />
                                        </Grid>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="roRI" Header="RI" Width="Auto" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding RI}" ToolTipService.ShowDuration="60000" ></Label>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridCheckBoxColumn Header="Paid" Width="40" Binding="{Binding Paid}" />
                <DataGridCheckBoxColumn Header="Adj" Width="30" Binding="{Binding Adjustment}" />
            </DataGrid.Columns>
        </DataGrid>

Edit 2: Actually, I don't even need to vertically align them. Just adding a little padding to the top so it'll line up with the top of the Template Columns.

Upvotes: 0

Views: 6967

Answers (1)

Xcalibur37
Xcalibur37

Reputation: 2323

have you tried this:

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="VerticalAlignment" Value="Center" />
</Style>

Upvotes: 2

Related Questions