Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide the header of a WPF ListView?

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> 
like image 588
Ozplc Avatar asked Mar 10 '09 22:03

Ozplc


1 Answers

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> 
like image 175
Ray Avatar answered Sep 21 '22 12:09

Ray