I
I
Igor Antonik2015-03-31 00:43:23
WPF
Igor Antonik, 2015-03-31 00:43:23

How to combine ListView and GridView when setting style for ListView in WPF (C#)?

There is a ListView in which the content from the ObservableCollection is displayed in columns. To display content in columns, a GridView is attached to the ListView, declared in Window.Resources as a static resource:

<GridView x:Key="GridView1">
            <GridView.Columns>
                <GridViewColumn Header="Имя" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn>
                <GridViewColumn Header="Тип" DisplayMemberBinding="{Binding Path=Type}" Width="60"></GridViewColumn>
                <GridViewColumn Header="Размер" DisplayMemberBinding="{Binding Path=Size}" Width="60"></GridViewColumn>
                <GridViewColumn Header="Дата" DisplayMemberBinding="{Binding Path=Date}" Width="130"></GridViewColumn>
            </GridView.Columns>
        </GridView>

Listview declaration:
<ListView View="{StaticResource GridView1}" Name="folderPanel1"></ListView>

Without a style, the output by columns works fine, but once the style is attached, the column headings disappear (the content is displayed normally):
<Style TargetType="{x:Type ListView}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListView}">
                        <Border 
                            Name="Button" 
                            Background="{StaticResource ListViewBackgroundBrush}"
                            BorderBrush="{StaticResource StandartBorderBrush}"
                            BorderThickness="1" CornerRadius="3">
                            <ScrollViewer Focusable="False">
                                <ItemsPresenter Margin="2"></ItemsPresenter>
                            </ScrollViewer>                            
                        </Border>    
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Style is just a blank, do not pay attention to simplicity. How can I make the column headings disappear?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Vishnyakov, 2015-04-06
@Svjatogor

Try

<ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}" Focusable="False">
    <ItemsPresenter Margin="2"/>
</ScrollViewer>

Taken from here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question