如何隐藏列表视图WPF的标题?

我想能够隐藏在WPF ListView中的每个网格列顶部的标题。

这是我的ListView的XAML:

<Window x:Class="ListViewTest.Test0.ListViewTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Empty ListView Grid" Height="216" Width="435" FlowDirection="LeftToRight" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.IsSharedSizeScope="False"> <Window.Resources> <XmlDataProvider x:Key="CustomersDS" Source="C:\data.xml"/> </Window.Resources> <ListView Margin="0,0,0,50" ItemTemplate="{DynamicResource CustomerTemplate}" ItemsSource="{Binding Source={StaticResource CustomersDS}, XPath=/Customers/Customer}"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding XPath=Code}"/> <GridViewColumn DisplayMemberBinding="{Binding XPath=Name}"/> <GridViewColumn DisplayMemberBinding="{Binding XPath=Country}"/> </GridView> </ListView.View> </ListView> </Window> 

我绑定这个数据是:

  <Customers> <Customer> <Code>1234</Code> <Name>EPI</Name> <Country>Sesame Street</Country> </Customer> <Customer> <Code>3234</Code> <Name>Paul</Name> <Country>United Kingdom</Country> </Customer> <Customer> <Code>3344</Code> <Name>Juan</Name> <Country>Spain</Country> </Customer> <Customer> <Code>4321</Code> <Name>Dodo</Name> <Country>Mars</Country> </Customer> </Customers> 

像这样定义一个样式

 <Window.Resources> .... <Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}"> <Setter Property="Visibility" Value="Collapsed" /> </Style> </Window.Resources> 

像这样应用

 <GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}"> .... </GridView> 

感谢这个解决scheme。 你也可以像这样内联Style

 <ListView> <ListView.Resources> <Style TargetType="GridViewColumnHeader"> <Setter Property="Visibility" Value="Collapsed" /> </Style> </ListView.Resources> <ListView.View> <GridView> <!-- ... --> </GridView> </ListView.View> </ListView> 

(另外,您使用的{x:Type}表示法似乎并不需要)

您可以应用Ray的解决scheme的另一种方式是这样的:

 <ListView> <ListView.View> <GridView> <GridView.ColumnHeaderContainerStyle> <Style TargetType="GridViewColumnHeader"> <Setter Property="Visibility" Value="Collapsed" /> </Style> </GridView.ColumnHeaderContainerStyle> </GridView> </ListView.View> </ListView> 

该解决scheme直接设置样式属性,而不是创build自动应用的资源。 不是说更好,只是另一种方式…