我希望能够在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>

.net相关问答推荐

SLN配置文件:映射问题

避免函数和其他对象之间的相互递归的模式?

与 Datagrid 的 SelectedItem 链接时的 WPF RadioButton 绑定问题

在 Inno Setup 中判断给定服务的依赖服务

AppShell - 返回导航失败,匹配的路由不明确......但我只注册了一次路由

dotnet ef dbcontext scaffold command --data-annotations 或 -d 命令行参数似乎不起作用

AsyncLocal 的语义与逻辑调用上下文有何不同?

SetupSet() 已过时.代替什么?

在 ASP.NET MVC 中我可以在哪里放置自定义类?

您如何确定两个 HashSet 是否相等(按值,而不是按引用)?

.Include() 与 .Load() 在 EntityFramework 中的性能

注册 COM 互操作与使程序集 COM 可见

获取当前方法的名称

Linq查询分组并 Select 第一个项目

如何从 .net 中的数组类型获取数组项类型

在 C# 中转义命令行参数

.NET 中是否有可序列化的通用键/值对类?

在 .NET 中填充整数列表

如何在不使用 3rd 方库的情况下登录 C#?

浮动与双重性能