CollectionViewSource(players)にバインドされたDataGridを使用しており、それ自体がListBox(levels)の現在選択されているアイテムにバインドされています。各アイテムには、DataGridで並べ替え/表示されるコレクションが含まれています。
<ListBox Name="lstLevel"
DisplayMemberPath="Name"
IsSynchronizedWithCurrentItem="True" />
..。
<!-- DataGrid source, as a CollectionViewSource to allow for sorting and/or filtering -->
<CollectionViewSource x:Key="Players"
Source="{Binding ElementName=lstLevel,
Path=SelectedItem.Players}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
..。
<DataGrid Name="lstPlayers" AutoGenerateColumns="False"
CanUserSortColumns="False"
ItemsSource="{Binding Source={StaticResource Players}}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="{Binding Path=Name, Mode=TwoWay}"
Width="*" />
<DataGridTextColumn Header="Age"
Binding="{Binding Path=Age, Mode=TwoWay}"
Width="80">
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
(ここにC#コード全体、ここにXAMLコード、ここにテストプロジェクト全体-DataGridに加えて、DataGridの問題ではないことを確認するために、プレーヤー用の単純なリストボックスを追加しました)
問題は、プレーヤーが最初に表示されたときに並べ替えられることですが、リストボックスから別のレベルを選択するとすぐに並べ替えられなくなります。また、プレイヤーが最初に表示されたときに名前を変更すると、変更に応じて名前が並べ替えられますが、レベルが変更されると、名前は並べ替えられなくなります。
したがって、CollectionViewSourceのソースを変更すると、並べ替え機能が機能しなくなるように見えますが、その理由も修正方法もわかりません。誰かが私が間違っていることを知っていますか?
(私はフィルターを使ってテストを行いましたが、それは期待どおりに機能し続けました)
フレームワークは.NET4です。