Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid Cell Padding not being applied #977

Closed
jimbobsmith opened this issue Jan 23, 2014 · 3 comments
Closed

DataGrid Cell Padding not being applied #977

jimbobsmith opened this issue Jan 23, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@jimbobsmith
Copy link

Hi. I've noticed when creating a cell style, the padding property is not being applied. If this is by design, please delete this ticket. Otherwise, to do this I simply template bound the ContentPresenter's margin to padding.

<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
     VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
     Margin="{TemplateBinding Padding}"
...

MOD EDIT: Please surround code in ```s. ~@Amrykid

@AzureKitsune
Copy link
Member

I am not sure if this is by design. Could you show us a picture showing the behavior?

@jimbobsmith
Copy link
Author

This is what i get when i set a cell style with padding:

image

The xaml is:

 <Style x:Key="CellStyleWithPadding" TargetType="DataGridCell" >
                <Setter Property="Padding" Value="10"/>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <DataGrid x:Name="DataGrid"
                  AutoGenerateColumns="False"
                  CellStyle="{StaticResource CellStyleWithPadding}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
                <DataGridTextColumn Header="Age" Binding="{Binding Age}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

When I rewrite the cell template, I get:
image

and the xaml for this is:

            <Style  x:Key="CellStyleWithPadding" TargetType="{x:Type DataGridCell}" 
                    BasedOn="{StaticResource MetroDataGridCell}" >
                <Setter Property="Padding" Value="10"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Border BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Background="{TemplateBinding Background}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                                <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Margin="{TemplateBinding Padding}"                                          
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <DataGrid x:Name="DataGrid"
                  AutoGenerateColumns="False"
                  CellStyle="{StaticResource CellStyleWithPadding}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
                <DataGridTextColumn Header="Age" Binding="{Binding Age}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

@punker76
Copy link
Member

punker76 commented Jun 4, 2014

@jimbobsmith here is an example after #1393

<Style x:Key="CellStyleWithPadding"
       TargetType="DataGridCell"
       BasedOn="{StaticResource MetroDataGridCell}">
    <Setter Property="Padding"
            Value="10" />
</Style>

<DataGrid x:Name="DataGrid"
          AutoGenerateColumns="False"
          MinRowHeight="25"
          RowHeight="NaN"
          CellStyle="{StaticResource CellStyleWithPadding}">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
        <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
        <DataGridTextColumn Header="Age" Binding="{Binding Age}"/>
    </DataGrid.Columns>
</DataGrid>

@punker76 punker76 mentioned this issue Jun 4, 2014
33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants