首页 > 解决方案 > ListCollectionView.CustomSort 是否使用稳定的排序?

问题描述

我使用 ListCollectionView 和 Comparer 对 xaml 中的列表进行排序,而在 C# 的另一个位置,我需要使用相同的 Comparer 以完全相同的方式进行排序,因此排序需要稳定。

这种排序是不稳定的:

myCollectionCopy = myCollection.ToList();
myCollectionCopy.Sort(myComparer);

这种排序是稳定的:

myCollection.OrderBy(x => x.MyProperty, myComparer)

但是我无法从文档中弄清楚 ListCollectionView 在设置时是否使用了稳定的排序

myListCollectionView.CustomSort = myComparer;

另请参阅:https ://social.msdn.microsoft.com/Forums/vstudio/en-US/f5ea4976-1c3d-4e10-90e7-c7a0491fc28a/stable-sort-using-listt?forum=netfxbcl

标签: c#wpfsortingxamlcollectionviewsource

解决方案


推荐阅读