/// <summary> /// Begins observing the given notifying collection. /// </summary> /// <param name="notifyingCollection"></param> public void ObserveCollection(INotifyCollectionChanged notifyingCollection) { notifyingCollection.ThrowIfNull("notifyingCollection"); if (IsDisposed) { return; } if (myObservedCollections.ContainsKey(notifyingCollection)) { return; } myObservedCollections[notifyingCollection] = () => notifyingCollection.CollectionChanged -= myCollectionChangedEventHandler; NotificationChainPropertyAttribute.CallProperties(notifyingCollection); notifyingCollection.CollectionChanged += myCollectionChangedEventHandler; var enumerable = notifyingCollection as IEnumerable; if (enumerable != null) { foreach (var item in enumerable) { var inpc = item as INotifyPropertyChanged; if (inpc != null) { base.Observe(inpc); } } } }
public CollectionNotificationChainManager(INotifyCollectionChanged notifyingCollection) : this() { notifyingCollection.ThrowIfNull("notifyingCollection"); ObserveCollection(notifyingCollection); }
/// <summary> /// Stop observing the given notifying collection. /// </summary> /// <param name="notifyingCollection"></param> public void StopObservingCollection(INotifyCollectionChanged notifyingCollection) { notifyingCollection.ThrowIfNull("notifyingCollection"); if (IsDisposed) { return; } Action removeHandler; if (!myObservedCollections.TryGetValue(notifyingCollection, out removeHandler)) { return; } lock (this) { removeHandler(); var enumerable = notifyingCollection as IEnumerable; if (enumerable != null) { foreach (var item in enumerable) { base.StopObserving(item); } } myObservedCollections.Remove(notifyingCollection); } }
/// <summary> /// Begins observing the given notifying collection. /// </summary> /// <param name="notifyingCollection"></param> public void ObserveCollection(INotifyCollectionChanged notifyingCollection) { notifyingCollection.ThrowIfNull ("notifyingCollection"); if (IsDisposed) return; if (myObservedCollections.ContainsKey (notifyingCollection)) return; myObservedCollections[notifyingCollection] = () => notifyingCollection.CollectionChanged -= myCollectionChangedEventHandler; NotificationChainPropertyAttribute.CallProperties (notifyingCollection); notifyingCollection.CollectionChanged += myCollectionChangedEventHandler; var enumerable = notifyingCollection as IEnumerable; if (enumerable != null) { foreach (var item in enumerable) { var inpc = item as INotifyPropertyChanged; if (inpc != null) base.Observe (inpc); } } }
public CollectionNotificationChainManager(INotifyCollectionChanged notifyingCollection) : this() { notifyingCollection.ThrowIfNull ("notifyingCollection"); ObserveCollection (notifyingCollection); }
/// <summary> /// Stop observing the given notifying collection. /// </summary> /// <param name="notifyingCollection"></param> public void StopObservingCollection(INotifyCollectionChanged notifyingCollection) { notifyingCollection.ThrowIfNull ("notifyingCollection"); if (IsDisposed) return; Action removeHandler; if (!myObservedCollections.TryGetValue (notifyingCollection, out removeHandler)) return; lock (this) { removeHandler (); var enumerable = notifyingCollection as IEnumerable; if (enumerable != null) { foreach (var item in enumerable) { base.StopObserving (item); } } myObservedCollections.Remove (notifyingCollection); } }