How can I hide the header of a WPF ListView?

后端 未结 3 1543
慢半拍i
慢半拍i 2021-01-30 10:04

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:

   

        
相关标签:
3条回答
  • 2021-01-30 10:25

    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>
    
    0 讨论(0)
  • 2021-01-30 10:32

    Another way you can apply Ray's solution is like this:

    <ListView>
        <ListView.View>
            <GridView>
                <GridView.ColumnHeaderContainerStyle>
                    <Style TargetType="GridViewColumnHeader">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </Style>
                </GridView.ColumnHeaderContainerStyle>
            </GridView>
        </ListView.View>
    </ListView>
    

    The solution sets the style property directly rather than creating a resource that is automatically applied. Not saying it's better, just another way...

    0 讨论(0)
  • 2021-01-30 10:33

    Thanks for this solution. 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>
    

    (Also, the {x:Type} notation you used doesn't seem to be needed)

    0 讨论(0)
提交回复
热议问题