Following this Topics Xceed WPF propertyGrid show item for expanded collection, how is it possible with XAML to sort the list by Name when Binding to Classes ? Everytime I would like to add a new Item it should be immediately sorted. It doesn't work because if I use Classes.orderby(x=>x.name) it breaks all the bindings?
Asked
Active
Viewed 98 times
1 Answers
0
Hello After lot's of time the solution is at the same time and not, but here I gave you all the solution: 1) the getters and setter for your 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;
}
}
And your Collection have to inherit from ObservableCollection but at the Same time to get an Extension to sort()
here we go:
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
{
}
and YourPoints have to inherit from IComparable

littlecloud47
- 1
- 1