SortedSet with INotifyPropertyChanged

I have something like this:

public class CPerson: INotifyPropertyChanged
public class CPeople: SortedSet<CPerson>
public class CMain
{
    private CPeople _people;
}

I want to know in CMain, if something has been changed to CPeoplea new person has been added or removed, or something has been changed in some CPersonin CPeople, I realized INotifyPropertyChangedon CPersonbut I do not have a brilliant idea that the interface implemented in the classroom CPeopleand how good sense to leave the PropertyChangedevent behind CPeoplebefore CMain.

Can anyone help me? Hey.

+3
source share
3 answers

ObservableCollection<Person>. SortedSet, INotifyCollectionChanged INotifyPropertyChanged.

, , , , SortedSet, :

public class ObservableSortedSet<T> : ICollection<T>, 
                                      INotifyCollectionChanged, 
                                      INotifyPropertyChanged
{
    readonly SortedSet<T> _innerCollection = new SortedSet<T>();

    public IEnumerator<T> GetEnumerator()
    {
        return _innerCollection.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    public void Add(T item)
    {
        _innerCollection.Add(item);
        // TODO, notify collection change
    }

    public void Clear()
    {
        _innerCollection.Clear();
        // TODO, notify collection change
    }

    public bool Contains(T item)
    {
        return _innerCollection.Contains(item);
    }

    public void CopyTo(T[] array, int arrayIndex)
    {
        _innerCollection.CopyTo(array, arrayIndex);
    }

    public bool Remove(T item)
    {
        _innerCollection.Remove(item);
        // TODO, notify collection change
    }

    public int Count
    {
        get { return _innerCollection.Count; }
    }

    public bool IsReadOnly
    {
        get { return ((ICollection<T>)_innerCollection).IsReadOnly; }
    }

    // TODO: possibly add some specific methods, if needed

    public event NotifyCollectionChangedEventHandler CollectionChanged;
    public event PropertyChangedEventHandler PropertyChanged;
}
+6

SortedSet < > , ( SortedSet < > ), INotifyCollectionChanged. , SortedSet < > ObservableCollection < > .

+1

IPeopleChanged .. , PersonAdded(Person p), PersonRemoved(Person p) - PersonPropertyChanged(Person p,PropertyChangedEventArgs arg), , , CMain.

, 3 . , , , , PropertyChanged .

0

Source: https://habr.com/ru/post/1776981/


All Articles