代码之家  ›  专栏  ›  技术社区  ›  Willy

DataGridCell在对DataGridCell应用填充后,在WPF的顶部和底部显示空格

  •  0
  • Willy  · 技术社区  · 6 年前

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

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

    <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 回复  |  直到 6 年前