ObservableCollection没有自带的sort排序功能,那么可以写一个扩展方法:

public static void Sort<T>(this ObservableCollection<T> collection)
{
    collection.Sort(Comparer<T>.Default);
}
public static void Sort<T>(this ObservableCollection<T> collection, IComparer<T> comparer)
{

    if (collection == null || collection.Count <= 1) return;

    var lst = collection.ToList();
    lst.Sort(comparer);
    var count = collection.Count;
    for (int m = 0; m < count; m++)
    {
        var dex = collection.IndexOf(lst[m]);
        if (dex == m) continue;
        collection.Move(dex, m);
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2021-05-25
  • 2022-12-23
  • 2021-11-28
  • 2021-10-22
相关资源
相似解决方案