I am trying to display Information
objects grouped by Context
property with in the UWP DataGrid using the code below. The first method creates a ObservableCollection<GroupInfoCollection<Information>>();
which is set to the CollectionViewSource.Source
as shown in second part. And the XAML used is shown at the very end.
I can see the group headings as Group
in UI, but without any subitems. I am not sure what I am missing. Also the group headers are not showing the Context
property name.
var query = from item in exception.Information
group item by item.Context into g
select new { GroupName = g.Key, Items = g };
var information = new ObservableCollection<GroupInfoCollection<Information>>();
foreach (var group in query)
{
var info = new GroupInfoCollection<Information>
{
Key = group.GroupName
};
foreach (var item in group.Items)
{
info.Items.Add(item);
}
information.Add(info);
}
return information;
CollectionViewSource groupedItems = new CollectionViewSource
{
IsSourceGrouped = true,
Source = information // returned from above method
};
InformationGrid.ItemsSource = groupedItems.View;
<controls1:DataGrid x:Name="InformationGrid" AutoGenerateColumns="False" >
<controls1:DataGrid.Columns>
<controls1:DataGridTemplateColumn Header="Name" Width="48">
<controls1:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="jama:Information">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="{x:Bind local:JamaOptionPage.GetGlyph(Level)}"/>
</DataTemplate>
</controls1:DataGridTemplateColumn.CellTemplate>
</controls1:DataGridTemplateColumn>
<controls1:DataGridTemplateColumn Header="Name" Width="220">
<controls1:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="jama:Information">
<HyperlinkButton Content="{x:Bind Name}" NavigateUri="{x:Bind Link}" />
</DataTemplate>
</controls1:DataGridTemplateColumn.CellTemplate>
</controls1:DataGridTemplateColumn>
<controls1:DataGridTextColumn Header="Error" Binding="{Binding Message}"/>
</controls1:DataGrid.Columns>
</controls1:DataGrid>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…