0
在下面的窗口中,为什么页眉的填充为2/3,即使我使用下面的代码明确地将其设置为0? (而且可以把它看成0探听):WPF DataGrid奇怪的页眉填充行为
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</DataGridTemplateColumn.HeaderStyle>
这给了我下面的(头有边距):
但只要我将其更改为0以外的东西,例如:
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Padding" Value="0,1" />
<Setter Property="Margin" Value="0" />
</Style>
</DataGridTemplateColumn.HeaderStyle>
填充未设置为默认值。我假设有一些代码在WPF库中的某处?
已经有人穿过这之前来想通了,为什么我花一个下午查明原因之前?
全面测试代码:
<Window x:Class="WpfApplication1.GridSpacing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid>
<DataGrid.Items>
<system:String>Test</system:String>
</DataGrid.Items>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Test"
Background="Aquamarine"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Padding" Value="0" />
</Style>
</DataGridTemplateColumn.HeaderStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Test" Background="Aquamarine"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>