我有一个如下所示的DataGrid:
<DataGrid x:Name="RecodersSummary" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness ="1" IsReadOnly ="True" Loaded="RecordersSummary_Loaded" GridLinesVisibility="All" AutoGenerateColumns="False">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1,1,1,1"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="{DynamicResource Summary_FirstColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Summary}"/>
<DataGridTextColumn Header="{DynamicResource Summary_SecondColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Totals}"/>
<DataGridTextColumn Header="{DynamicResource Summary_ThirdColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Centralized}"/>
<DataGridTextColumn Header="{DynamicResource Summary_ForthColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Standalone}"/>
<DataGridTextColumn Header="{DynamicResource Summary_FifthColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Temporary}"/>
<DataGridTextColumn Header="{DynamicResource Summary_SixthColumnHeader}" Width="Auto" IsReadOnly="True" Binding="{Binding Path=Other}"/>
</DataGrid.Columns>
这样一来,列标题中显示的文本宽度和文本本身一样宽,显得很拥挤。
在上面的示例中,我该如何在文本左右两侧添加填充以使标题列比文本略宽一些?
<Setter Property="Padding" Value="12,6" />
添加到DataGridColumnHeader
样式中。 - Nkosi