How can I hide the header of a WPF ListView?
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>
You can also put the Style
inline like so:
<ListView>
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<!-- ... -->
</GridView>
</ListView.View>
</ListView>
This ensures that the style will only be applied to the desired control (i.e., without unintentionally affecting any additional controls that may be within the XAML scope).
[edit: 2022] A better solution (not mentioned elsewhere on this page) is to entirely disable the header, rather than collapse it. If you never plan to "uncollapse" (show) the header, there's no reason the WPF layout engine should have to consider it at all:
<ListView>
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Template" Value="{x:Null}" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<!-- ... -->
</GridView>
</ListView.View>
</ListView>
The only difference from above is to set the control Template
of the sub-scoped GridViewColumnHeader
instances to {x:Null}
. This allows WPF to avoid preparing for header instance(s) that are never going to be rendered anyway.