I want to be able to hide the header at the top of each grid column in a WPF ListView.

This is the XAML for my ListView:

   <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>

The data I am binding this to is:

 <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>

推荐答案

Define a Style like so

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

Apply it like so

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

.net相关问答推荐

将多行参数传递给Power Shell中的DotNet Pack命令

.NET最小API BadRequest响应不返回正文

如何使用 awslocal 通过 localstack 中的 cloudwatch events/eventbridge 触发 lambda

如何在 NET 5 / 6 中使用 Direct3D11CaptureFramePool

在 web api 控制器(.net 核心)中使用 async/await 或任务

使用 .NET 在 Windows 中创建弹出式 toastr 通知

如何将字符串列表数据绑定到 WPF/WP7 中的 ListBox?

InternalsVisibleTo 属性不起作用

Convert.ToBoolean 和 Boolean.Parse 不接受 0 和 1

WCF服务客户端:内容类型text/html;响应消息的charset=utf-8 与绑定的内容类型不匹配

在生产环境中部署调试符号(pdb 文件)有什么风险?

beforefieldinit 标志有什么作用?

无法加载文件或程序集Antlr3.Runtime (1)或其依赖项之一

更改 SqlConnection 超时

在 .NET 中,null 的哈希码是否应该始终为零

嵌套的 Try/Catch 块是个坏主意吗?

将控制台输出镜像到文件

没有科学记数法的双精度字符串转换

在构建事件命令行中放置注释的正确方法?

捕获控制台退出 C#