如何隐藏WPF ListView的标题? [英] How can I hide the header of a WPF ListView?

查看:142
本文介绍了如何隐藏WPF ListView的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在WPF ListView中的每个网格列的顶部隐藏标题.

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

这是我的ListView的XAML:

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>

我要绑定到的数据是:

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

这篇关于如何隐藏WPF ListView的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆