之前用到的一段代码,记录一下
1 public static class ObservableExtension 2 { 3 public static void Sort(this Collection source, Func keySelector) 4 { 5 List sortedList = source.OrderBy(keySelector).ToList(); 6 source.Clear(); 7 foreach (var sortedItem in sortedList) 8 source.Add(sortedItem); 9 }10 11 public static void Sort (this ObservableCollection collection) where T : IComparable12 {13 List sortedList = collection.OrderBy(x => x).ToList();14 for(int i = 0;i