Xaml 如何删除ListView GroupStyle标题分隔符行?
在windows universal platform上的ListView中,使用ListView分组时,组标题下方有一个难看的分隔符行。甚至微软自己也在应用程序中删除了这一行。在实时可视化树中,您可以看到它是GridViewHeaderItem中的矩形。我读过,可以将其高度设置为0。我该怎么做 下面是设置标题项文本的代码:Xaml 如何删除ListView GroupStyle标题分隔符行?,xaml,listview,uwp,Xaml,Listview,Uwp,在windows universal platform上的ListView中,使用ListView分组时,组标题下方有一个难看的分隔符行。甚至微软自己也在应用程序中删除了这一行。在实时可视化树中,您可以看到它是GridViewHeaderItem中的矩形。我读过,可以将其高度设置为0。我该怎么做 下面是设置标题项文本的代码: <ListView.GroupStyle> <GroupStyle HidesIfEmpty="True" > <GroupSt
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="True" >
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
您可以在generic.xaml中找到所有默认样式 C:\ProgramFiles(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="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ListViewHeaderItemThemeFontSize}" />
<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="{ThemeResource ListViewHeaderItemMinHeight}"/>
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewHeaderItem">
<StackPanel Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter x:Name="ContentPresenter"
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Rectangle Stroke="{ThemeResource SystemControlForegroundBaseLowBrush}"
StrokeThickness="0.5"
Height="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="12,8,12,0"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
只需将该样式复制到项目的ResourceDictionary中,并删除罪魁祸首矩形(因此只有ContentPresenter保留为子元素)
是否有方法在不覆盖默认样式的情况下执行此操作?我特别想把它放在一个控件上。你可以创建一个自定义控件,并将修改后的样式设置为该控件的默认样式。您可以将SystemControlForegroundBaseLowBrush
更改为页面背景(尽管这可能有副作用)。真正的问题是默认的StrokeThickness
是一个固定值,而不是一个绑定。对于gridview也很有用
<Rectangle Stroke="{ThemeResource SystemControlForegroundBaseLowBrush}"
StrokeThickness="0.5"
Height="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="12,8,12,0"/>