gpt4 book ai didi

c# - 在 WPF 中向 DataGridTextColumn 添加填充

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:28 24 4
gpt4 key购买 nike

我有以下数据网格:

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

有了这个,列标题中显示的文本宽度与文本宽度相同,看起来很局促。

在上面的示例中,如何在文本的左右添加填充以使标题栏比文本稍宽?

最佳答案

您可以将填充应用于列标题样式。

<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 x:Key="DataGrid_ColumnHeadStyle1" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1,1,1,1"/>
<Setter Property="Padding" Value="12,6,12,6"/>
</Style>
<Style TargetType="{x:Type DataGrid}">
<Setter Property="ColumnHeaderStyle" Value="{StatisResource DataGrid_ColumnHeadStyle1}"/>
</Style>
</DataGrid.Resources>
<!-- code removed for brevity -->
</DataGrid>

您也可以直接将样式应用到网格。

<DataGrid x:Name="RecodersSummary" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness ="1" IsReadOnly ="True" Loaded="RecordersSummary_Loaded" GridLinesVisibility="All" AutoGenerateColumns="False">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1,1,1,1"/>
<Setter Property="Padding" Value="12,6,12,6"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<!-- code removed for brevity -->
</DataGrid>

关于c# - 在 WPF 中向 DataGridTextColumn 添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37480335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com