DataGridCell showing blank spaces at top and bottom in WPF after applying padding to DataGridCell

141 Views Asked by At

I have below Style defined for DataGridCell:

<Style x:Key="MyDataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="Padding" Value="5"/> <!-- Padding cell -->
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                <Border Padding="{TemplateBinding Padding}" 
                        BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                        Background="{TemplateBinding Background}" SnapsToDevicePixels="True" VerticalAlignment="Center">
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

And then I apply it to my datagrid, but there are three columns (below shown) that are not displayed well, I mean, some blank space is left at top and bottom of the cell content.

<dg:DataGrid x:Name="MyDataGrid" SelectionMode="Single" 
             AlternationCount="2" AlternatingRowBackground="Bisque"
             Focusable="False" SelectionUnit="FullRow"
             CellStyle="{StaticResource MyDataGridCellStyle}">

   <dg:DataGrid.Columns>

       <!-- THERE ARE MORE COLUMNS. I ONLY SHOW HERE THE ONES THAT ARE DISPLAYED BAD -->
       <dg:DataGridTextColumn x:Name="Col2" 
                              Header="Col2Name" 
                              MinWidth="65" Width="auto"
                              IsReadOnly="True"                                               
                              Binding="{Binding Path=Col2Value}" />

       <dg:DataGridTextColumn x:Name="Col3" 
                              Header="Col3Name" 
                              MinWidth="55" Width="auto"
                              IsReadOnly="True"
                              Binding="{Binding Path=Col3Value}" />

       <dg:DataGridTextColumn x:Name="Col5"
                              Header="Date"
                              MinWidth="75" Width="auto"
                              IsReadOnly="True"
                              Binding="{Binding Path=Date, StringFormat='{}{0:dd/MM/yyyy HH:mm:ss}'}">

   </dg:DataGrid.Columns>
</dg:DataGrid>

Below the screenshot with the problem:

enter image description here I pixeled the information for confidentiality.

0

There are 0 best solutions below