我希望能够在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相关问答推荐

为什么在WinForm应用程序中创建组件类椭圆会在www.example.com中没有响应

Docker镜像mcr.microsoft.com/dotnet/aspnet:8.0不能在Windows上构建

防止在 .NET 上构建路径中的反斜杠以进行跨平台部署

将日期时间转换为日期格式 dd/mm/yyyy

查找 2 个已知值之间的字符串

C# 时间跨度毫秒与 TotalMilliseconds

File.ReadAllLines() 和 File.ReadAllText() 有什么区别?

如何在 C# 中创建 Word 文档?

使用多个 MemoryCache 实例

什么版本的 .NET 附带什么版本的 Windows?

哪个密码字符在 winforms 文本框中显示黑点 (•)?

为什么 C# 不推断我的泛型类型?

将记录器作为单身人士是一个好习惯吗?

让 String.Replace 只打整个单词的方法

将 Dictionary 转换为匿名对象?

使用 LINQ 搜索树

为 webClient.DownloadFile() 设置超时

NServiceBus 与 MassTransit

从 Visual Studio 2015 发布 - 允许不受信任的证书

无法添加对 dll 的引用