在对DataGridCell应用填充之后,DataGridCell在WPF中顶部和底部显示空白

时间:2018-11-30 08:47:51

标签: c# wpf datagrid datagridcell

我在下面为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>

然后将其应用于我的数据网格,但是三列(如下所示)显示得不好,我的意思是,单元格内容的顶部和底部都留有一些空白。

<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>

下面的屏幕截图出现问题:

enter image description here我为保密性对信息进行了像素化。

0 个答案:

没有答案