I want to list players name under category(Grouping). So I used ListView. I have a ViewModel class which has Observable Collection of PlayerData and i set this observableCollection to CollectionViewSource . when i try to set CollectionViewSource to ListView ItemSource,it throws error!
My Complete Source Code : --> Project Link
I also want to Customize the ListView GroupHeaderTemplate . How to do that?
CodePudding user response:
You should assign CollectionViewSource view property to The ListView ItemsSource. please try the following
listView.ItemsSource = collectionViewSource.View;
One more thing, you have not specificed listview GroupStyle please refer the following xaml code
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="local:ListViewGroup">
<Border>
<TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{x:Bind HeaderText}" />
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
Update
<GroupStyle x:Key="groupStyle">
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="local:ListViewGroup">
<Border>
<TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{x:Bind HeaderText}" />
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
Insert above style into GroupStyle
listView.GroupStyle.Add((GroupStyle)this.Resources["groupStyle"]);