在generic.xaml文件中可以找到所有的默认样式,路径为
C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10240.0\Generic
深入研究该文件,您也可以找到ListViewHeaderItem的默认样式:
<!-- Default style for Windows.UI.Xaml.Controls.ListViewHeaderItem -->
<Style TargetType="ListViewHeaderItem">
<Setter Property="FontFamily" Value="" />
<Setter Property="FontSize" Value="" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Margin" Value="0,0,0,4"/>
<Setter Property="Padding" Value="12,8,12,0"/>
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="MinHeight" Value=""/>
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewHeaderItem">
<StackPanel Background=""
BorderBrush=""
BorderThickness="">
<ContentPresenter x:Name="ContentPresenter"
Margin=""
Content=""
ContentTemplate=""
ContentTransitions=""
HorizontalContentAlignment=""
VerticalContentAlignment=""/>
<Rectangle Stroke=""
StrokeThickness="0.5"
Height="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="12,8,12,0"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
只需将该样式复制到您项目的ResourceDictionary中,并删除有问题的Rectangle(因此仅剩下ContentPresenter作为子元素)即可。
<Rectangle Stroke="{ThemeResource SystemControlForegroundBaseLowBrush}"
StrokeThickness="0.5"
Height="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="12,8,12,0"/>
SystemControlForegroundBaseLowBrush
更改为页面的背景色(尽管这可能会产生副作用)。真正的问题在于默认的StrokeThickness
是一个固定值而不是绑定值。 - Bart