I'm trying to do nested grouping on two levels using the WinRT ListView component. So far I haven't been able to transfer the samples I've found for WPF, because the WinRT components lack a few of the properties that exists in WPF - for instance the CollectionViewSource in WinRT doesn't have the GroupDescriptions property used to define several groups.
The view I'm trying to make is like this:

So far I've been able to get a view like this in WinRT - the version level is missing:

The XAML I've come up with so far has two CollectionViewSource objects where I set the Source of the categoryViewSource equal to the View of the versionViewSource. The ListView's ItemsSource is bound to the categoryViewSource. This obviously works at some extent, as I'm getting some data displayed.
<UserControl.Resources>
<DataTemplate x:Key="versionTemplate">
<TextBlock Margin="10" Style="{StaticResource SubheaderTextBlockStyle}" Foreground="{ThemeResource AccentColorBrush}">
<Run Text="{Binding VersionString}" /><Run Text=" (" /><Run Text="{Binding ReleaseDateString}" /><Run Text=")" />
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="categoryTemplate">
<TextBlock Margin="10" Style="{StaticResource SubheaderTextBlockStyle}" Foreground="{ThemeResource AccentColorBrush}" Text="{Binding Category}" />
</DataTemplate>
<DataTemplate x:Key="releaseNoteTemplate">
<TextBlock Margin="10" Style="{StaticResource BodyTextBlockStyle}" Text="{Binding Text}" />
</DataTemplate>
<local:ReleaseNotesTemplateSelector x:Key="releaseNotesTemplateSelector"
VersionTemplate="{StaticResource versionTemplate}"
CategoryTemplate="{StaticResource categoryTemplate}"/>
<CollectionViewSource x:Name="versionViewSource" IsSourceGrouped="True" ItemsPath="Categories" />
<CollectionViewSource x:Name="categoryViewSource" IsSourceGrouped="True" ItemsPath="Items" />
</UserControl.Resources>
<ListView ItemsSource="{Binding Source={StaticResource categoryViewSource}}"
ItemTemplate="{StaticResource releaseNoteTemplate}"
IsItemClickEnabled="False">
<ListView.GroupStyle>
<GroupStyle HeaderTemplateSelector="{StaticResource releaseNotesTemplateSelector}" />
</ListView.GroupStyle>
</ListView>
The Source properties are set in code behind like this:
if (this.DataContext is ReleaseNotesViewModel)
{
this.versionViewSource.Source = this.ViewModel.Versions;
this.categoryViewSource.Source = this.versionViewSource.View;
}
The ReleaseNotesTemplateSelector works like this:
public class ReleaseNotesTemplateSelector : DataTemplateSelector
{
public DataTemplate VersionTemplate { get; set; }
public DataTemplate CategoryTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is ReleaseNoteVersionViewModel)
return this.VersionTemplate;
else if (item is ReleaseNoteCategoryViewModel)
return this.CategoryTemplate;
return base.SelectTemplateCore(item, container);
}
}
I could of course continue using a hard typed view, but I would rather have a dynamically generated view if possible. Does anyone have a suggestion on how I can get nested grouping to display version number in the first group level?
