I have created my own collection and implemented INotifyCollectionChanged.
public class ObservableSortedSet<T> : SortedSet<T>, INotifyCollectionChanged
{
public event NotifyCollectionChangedEventHandler CollectionChanged;
public new bool Add(T item)
{
var result = base.Add(item);
if (result)
CollectionChanged?.Invoke(item,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
return result;
}
public new bool Remove(T item)
{
var result = base.Remove(item);
if (result)
CollectionChanged?.Invoke(item,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
return result;
}
public new void Clear()
{
base.Clear();
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
However when I try to use this collection as ItemsSource in views, they do not update automatically when I e.g. remove an item. As I seen in other questions here, I should implement INotifyCollectionChanged. I did this and yet it doesn't work. Any suggestions?