2016-11-16 66 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的

继承