如何隐藏一个ListView WPF的头?

编程入门 行业动态 更新时间:2024-10-09 17:20:27
本文介绍了如何隐藏一个ListView WPF的头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

这是XAML为我的ListView:

<窗​​口x:类=ListViewTest.Test0.ListViewTest    的xmlns =htt​​p://schemas.microsoft/winfx/2006/xaml/$p$psentation    的xmlns:X =htt​​p://schemas.microsoft/winfx/2006/xaml    标题=空的ListView网格高度=216宽度=435的FlowDirection =LeftToRight的Horizo​​ntalAlignment =拉伸VerticalAlignment =拉伸Grid.IsSharedSizeScope =FALSE>     < Window.Resources>         < XmlDataProvider X:关键=CustomersDS来源=C:\ data.xml的/>     < /Window.Resources>     < ListView的保证金=0,0,0,50的ItemTemplate ={DynamicResource CustomerTemplate}的ItemsSource ={绑定源= {的StaticResource CustomersDS},XPath的= /客户/顾客}>         < ListView.View>             < GridView控件>                 < GridViewColumn DisplayMemberBinding ={结合的XPath = code}/>                 < GridViewColumn DisplayMemberBinding ={结合的XPath =名}/>                 < GridViewColumn DisplayMemberBinding ={结合的XPath =国家}/>             < / GridView的>         < /ListView.View>     < / ListView控件> < /窗>

我结合这数据是:

<客户>   <客户>  < code> 1234< / code取代;  <名称>&EPI LT; /名称>  <国家>芝麻街< /国家>   < /客户>   <客户>  < code> 3234< / code取代;  <名称>保罗和LT; /名称>  <国家>英国< /国家>   < /客户>  <客户>  < code> 3344< / code取代;  <名称>&娟LT; /名称>  <国家>西班牙< /国家>   < /客户>  <客户>  < code> 4321< / code取代;  <名称>&突突LT; /名称>  <国家>火星< /国家>   < /客户> < /客户>

解决方案

定义一个样式像这样

< Window.Resources>     ....     <风格X:关键=myHeaderStyle的TargetType ={X:类型GridViewColumnHeader}>         < setter属性=能见度VALUE =折叠/>     < /样式和GT; < /Window.Resources>

应用它像这样

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

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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/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>

更多推荐

如何隐藏一个ListView WPF的头?

本文发布于:2023-06-11 03:30:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/625723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ListView   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!