我有一个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 事件中,我将排序和分组逻辑分配给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));
}
TestGroupConverter
在其转换方法中返回字符串的长度。
结果如下:
我希望这些组按升序排序,其中的项目按降序排序。但似乎SortDescription
未使用组内的 for 项目 - 它未按降序排序。
我不确定我做错了什么。