私は持っていますObservableCollection<string>:
public ObservableCollection<string> Collection { get; set; } = new ObservableCollection<string>
{
"AA",
"BB",
"CC",
"C",
"A",
"C",
"BBB",
"AAA",
"CCC"
};
Windowの AListBoxは、この Collection にバインドします。Window Loaded イベントでは、並べ替えとグループ化のロジックを の基になる ICollectionView に割り当てていCollectionます。
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
ICollectionView defaultView = CollectionViewSource.GetDefaultView(this.Collection);
defaultView.GroupDescriptions.Add(new PropertyGroupDescription(null, new TestGroupConverter()));
defaultView.SortDescriptions.Add(new SortDescription("", ListSortDirection.Ascending));
defaultView.SortDescriptions.Add(new SortDescription("", ListSortDirection.Descending));
}
TestGroupConverterconvert メソッドで文字列の長さを返します。
結果は次のとおりです。
グループが昇順で並べ替えられ、その中の項目が降順で並べ替えられることを期待していました。しかしSortDescription、グループ内の for アイテムが使用されていないようです — 降順でソートされていません。
何が間違っているのかわかりません。
