私のWPFアプリケーションでは、このDataGridでDataGridを使用していますが、 "City"という列名に基づいてデータベースからデータをグループ化する必要があります。私はmvvmアーキテクチャとリストメソッドを使用していません。私はICollectionViewのを使用して、パラメータとしてDataTableオブジェクトを渡され、これが私のC#のコードであるWPF DataGridでデータをグループ化する方法
ICollectionView cv = CollectionViewSource.GetDefaultView(dt);
cv.GroupDescriptions.Add(newPropertyGroupDescription("City"));
Hotels.ItemsSource = cv;
そして、これは私のXAMLコードですよ:
<Window.Resources>
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<StackPanel>
<TextBlock Text="{Binding City}" Name="grouping" Foreground="Black"></TextBlock>
<ItemsPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<DataGrid Background="Azure" ItemsSource="{Binding Hotels}" CanUserAddRows="False" Name="Hotels" Style="{StaticResource AzureDataGrid}" Margin="0,173,0,0">
<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource ResourceKey=GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>
</DataGrid>
それは私が結合していTextBlock内のテキストは表示されません。列名のテキストブロックが動作しません...してください。助けてください
編集
I'tは何も同じ結果:( – santhosh
を表示does'tそれはCollectionViewSourceオブジェクトで問題になることがあります。更新の答えを参照してください。 – Jacek
それが仕事ではありません申し訳ありません:( – santhosh