2016-11-16 67 views

回答

0

如何重新創建一個新的可觀察集合?

試試下面的代碼:

Classes = new ObservableCollection<string>(Classes.OrderBy(x => x.name)); 
0

您好時間的解決方案是在同一時間,而不是大量的經過,但在這裏,我給你所有的解決方案: 1)的getter和setter方法爲您的ObservableCollection

private TheCollection yourcollection; 
    public TheCollection Yourcollection{ 
     get{ 
      yourcollection.CollectionChanged -= Your_CollectionChanged; 

      // use sort-Extension to sort pointprofil 
      yourcollection.Sort(); 
      // read CollectionChange-Event 
      yourcollection.CollectionChanged += Your_CollectionChanged; 
      return yourCollection; 
     } 
} 

和你的收藏有從的ObservableCollection但同時繼承得到一個擴展排序()

她Ë我們去:

static class Extensions 

    public static void Sort<T>(this ObservableCollection<T> collection) where T : IComparable 
    { 
     List<T> sorted = collection.OrderBy(x => x).ToList(); 
     for (int i = 0; i < sorted.Count(); i++) 
      collection.Move(collection.IndexOf(sorted[i]), i); 
    } 
} 

public class YourCollections : ObservableCollection<YourPoints>, ICustomTypeDescriptor, INotifyPropertyChanged 
{ 

} 

和YourPoints必須從IComparable的

繼承