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進行分組。 我能夠顯示說明,但看不到任何行。 有人可以告訴我最新的代碼有什麼問題嗎?