I have a simple view with a ListView
, I would like the ListView
has two groups, a group for items with property complete= 1
and another group with complete= 0
.
This is my class:
public class myClass
{
public string name{ get; set; }
public bool complete{ get; set; }
}
This is my XML:
<ListView x:Name="MasterListView">
<ListView.GroupStyle>
<GroupStyle >
<GroupStyle.HeaderTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
<DataTemplate x:Key="MasterListViewItemTemplate" x:DataType="model:myClass">
<TextBlock Margin="0,5,5,5" Text="{x:Bind name}" FontSize="20" Style="{ThemeResource BaseTextBlockStyle}" />
</DataTemplate>
I tried a few examples but I could not find anything.
First, use a CollectionViewSource for content that presents a list of items that can be grouped or sorted.
Then, get the data, group the data and set the grouped data to the CollectionViewSource in code behind.
Following is the sample code I have verified:
MainPage.xaml
MainPage.xaml.cs
Following is the output: