我正在尝试显示我的EF查询结果(具有group by子句)并将其显示在DataGrid中。我想复制这里的例子
http://wpftutorial.net/DataGrid.html
所以这是我的XAML代码
<DataGrid ItemsSource="{Binding QueryResult}">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=ItemCount}"/>
<TextBlock Text="Items"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
</DataGrid>
这是我的ViewModel
internal void GenerateReport()
{
Data = Project.GetReport(); **// this is List<IGrouping<string, MyType>>**
//QueryResult is a ListCollectionView property
QueryResult= new ListCollectionView(Data);
QueryResult.GroupDescriptions.Add(new PropertyGroupDescription("train"));
}
这就是我的查询结果
我确实得到了正确的密钥,但是如果你查看我的代码,我就会有一个针对关键项的集合。这里没有显示。如何在每列火车上显示?
修改
我想我有更多细节。以下是我的QueryResult集合的样子
基本上我的QueryResult有10个项目,其中每个项目都有Name,Items和ItemsCounts。 每个项目本身都有1个项目,其中包含一个键和一个组。该组基本上包含我想要在我的DataGrid中显示的项目,这些项目是针对出现的父10条记录进行分组。