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.
CMain
CPeople
CPerson
INotifyPropertyChanged
PropertyChanged
Can anyone help me? Hey.
ObservableCollection<Person>. SortedSet, INotifyCollectionChanged INotifyPropertyChanged.
ObservableCollection<Person>
, , , , 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; }
SortedSet < > , ( SortedSet < > ), INotifyCollectionChanged. , SortedSet < > ObservableCollection < > .
IPeopleChanged .. , PersonAdded(Person p), PersonRemoved(Person p) - PersonPropertyChanged(Person p,PropertyChangedEventArgs arg), , , CMain.
IPeopleChanged
PersonAdded(Person p)
PersonRemoved(Person p)
PersonPropertyChanged(Person p,PropertyChangedEventArgs arg)
, 3 . , , , , PropertyChanged .
Source: https://habr.com/ru/post/1776981/More articles:Rails 3, mysql / mysql2 misinterprets some extracted rows as ASCII-8BIT - mysql[Sleep mode] Merging a temporary object with children - javamysql2 gem, Rails 3.0.3 and "incompatible character encodings" - mysqlRetrieving message time - erlangFolding by case class - scalaspring local data - springWhich PE viewer application do you prefer when working with Win32 libraries? - c #load a library of downloadable code from a library? - phpSSL для конкретных страниц/url-шаблонов в tomcat - javaphp curl, response detection - gzip or not - phpAll Articles