0
我必须将数据分组到数据网格中。 我已经做以下为:在datagrid中分组 - 行不显示
- 添加了风格资源为:
> <Style x:Key="GroupHeaderStyle" > TargetType="{x:Type GroupItem}"> > <Setter Property="Template"> > <Setter.Value> > <ControlTemplate TargetType="{x:Type GroupItem}"> > <Expander IsExpanded="False" > > > <Expander.Header> > <TextBlock Text="{Binding Name}"/> > </Expander.Header> > <ItemsPresenter /> > </Expander> > </ControlTemplate> > </Setter.Value> > </Setter> > </Style>
- 我已经应用了风格:
我有infoList作为的ObservableCollection和的ItemsSource如下分配了它:
的ListCollectionView LCV =新的ListCollectionView(infoList); lcv.GroupDescriptions.Add(new PropertyGroupDescription(“Author”)); dgAuthor.ItemsSource = lcv;
<dg:DataGrid Grid.Row="1" Name="dgAuthor" HorizontalScrollBarVisibility="Hidden" AutoGenerateColumns="False" RowHeaderWidth="17" RowHeight="25"> <dg:DataGrid.GroupStyle> <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}"> <GroupStyle.Panel> <ItemsPanelTemplate> <dg:DataGridRowsPresenter/> </ItemsPanelTemplate> </GroupStyle.Panel> </GroupStyle> </dg:DataGrid.GroupStyle> </dg:DataGrid>
其中Info是具有Author,Book,Year属性的类。
我必须在Author属性上对datagrid进行分组。 我能够显示说明,但看不到任何行。 有人可以告诉我最新的代码有什么问题吗?