开发者

GridView hide Items area

开发者 https://www.devze.com 2023-02-07 11:13 出处:网络
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).

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"  />
       开发者_StackOverflow         <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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消