thumbmunkeys
thumbmunkeys

Reputation: 20764

GridView hide Items area

I want to hide the items area of a GridView, so that only the columns headers are visible. The part below the column headers should be invisible (collapsed). Here is my futile attempt:

      <ListView ItemsSource="{Binding .}">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Height="0" Visibility="Collapsed"></StackPanel>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name"  />
                <GridViewColumn Header="Size" />
                <GridViewColumn Header="Date"  />

            </GridView>
        </ListView.View>
    </ListView>

So my question is, how can I hide the items area (the part below the column headers) of the gridview

Upvotes: 0

Views: 214

Answers (1)

michele
michele

Reputation: 2091

In listview, headers are shown using a GridViewHeaderRowPresenter. If you want to show only a header row, try to use this object in which you list the columns you need. With your example:

EDIT

//resources
<Window.Resources>
    <GridViewColumnCollection x:Key="HeaderColumns">
        <GridViewColumn Header="Name"  />
        <GridViewColumn Header="Size" />
        <GridViewColumn Header="Date"  />
    </GridViewColumnCollection>
</Window.Resources>

//in layout
<GridViewHeaderRowPresenter  Columns="{StaticResource HeaderColumns}" />

HTH

Upvotes: 1

Related Questions