コード例 #1
0
        /// <summary>
        /// コレクションの依存関係プロパティ変更イベントハンドラです。
        /// </summary>
        /// <param name="d">イベント発行元</param>
        /// <param name="e">イベント引数</param>
        private static void OnCollectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var colorMap = d as ColorMap;

            if (e.OldValue != null)
            {
                if (e.OldValue is INotifyCollectionChanged)
                {
#if NET4
                    (e.OldValue as INotifyCollectionChanged).CollectionChanged -= colorMap.OnCollectionChanged;
#else
                    CollectionChangedEventManager.RemoveHandler(e.OldValue as INotifyCollectionChanged, colorMap.OnCollectionChanged);
#endif
                }
            }
            if (e.NewValue != null)
            {
                if (e.NewValue is INotifyCollectionChanged)
                {
#if NET4
                    (e.OldValue as INotifyCollectionChanged).CollectionChanged += colorMap.OnCollectionChanged;
#else
                    CollectionChangedEventManager.AddHandler(e.NewValue as INotifyCollectionChanged, colorMap.OnCollectionChanged);
#endif
                }
            }

            colorMap.UpdateRendering_GraphBitmap();
        }
コード例 #2
0
 private void UnListenToCollectionChanges()
 {
     if (m_vector is INotifyCollectionChanged incc)
     {
         CollectionChangedEventManager.RemoveHandler(incc, OnCollectionChanged);
     }
 }
コード例 #3
0
        private static void AutoScrollPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var scroller = obj as ScrollViewer;

            if (scroller == null || args.OldValue == args.NewValue)
            {
                return;
            }

            if (args.OldValue != null)
            {
                var coll = (INotifyCollectionChanged)args.OldValue;
                CollectionChangedEventManager.RemoveHandler(coll, AutoScrollSource_CollectionChanged);
                WeakEventManager <ScrollViewer, SizeChangedEventArgs> .RemoveHandler(scroller, "SizeChanged", ScrollViewer_SizeChanged);

                WeakPair pair = Get(coll, (p, _, __) => p);
                if (pair != null)
                {
                    _pairs.Remove(pair);
                }
            }

            if (args.NewValue != null)
            {
                var coll = (INotifyCollectionChanged)args.NewValue;
                CollectionChangedEventManager.AddHandler(coll, AutoScrollSource_CollectionChanged);
                WeakEventManager <ScrollViewer, SizeChangedEventArgs> .AddHandler(scroller, "SizeChanged", ScrollViewer_SizeChanged);

                AddPair(coll, scroller);
            }
        }
コード例 #4
0
        private static void OnSourceErrorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var node = Scope.GetNode(d) as InputNode;

            if (node == null)
            {
                // this happens when disposing
                return;
            }

            var oldErrors = (ReadOnlyObservableCollection <ValidationError>)e.OldValue;

            if (ShouldTrack(oldErrors))
            {
                CollectionChangedEventManager.RemoveHandler(oldErrors, node.OnSourceErrorsChanged);
            }

            var newErrors = (ReadOnlyObservableCollection <ValidationError>)e.NewValue;

            node.ErrorCollection.Remove(oldErrors);
            node.ErrorCollection.Add(newErrors);

            if (ShouldTrack(newErrors))
            {
                CollectionChangedEventManager.AddHandler(newErrors, node.OnSourceErrorsChanged);
            }
        }
コード例 #5
0
        internal void Invalidate()
        {
            ClearAllCaches();

            if (List == null && ReadOnlyList == null)
            {
                if (Enumerable is INotifyCollectionChanged icc)
                {
#if SILVERLIGHT
                    // TODO: Implement weak event pattern
                    icc.CollectionChanged -= OnCollectionChanged;
#else
                    CollectionChangedEventManager.RemoveHandler(icc, OnCollectionChanged);
#endif
                }
            }

            Enumerable = null;

            DisposeEnumerator(ref _enumerator);
            DisposeEnumerator(ref _changeTracker);

            Collection     = null;
            List           = null;
            ReadOnlyList   = null;
            FilterCallback = null;
        }
コード例 #6
0
        public static IObservable <ItemAdded <T> > ObserveAddedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemAdded <T> >();

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                case NotifyCollectionChangedAction.Replace:
                    subject.OnNext(new ItemAdded <T>((T)e.NewItems[0], e.NewStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = 0; i < list.Count; ++i)
                    {
                        subject.OnNext(new ItemAdded <T>(list[i], i));
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
コード例 #7
0
        // Unhook a newly-deleted CollectionContainer
        private void RemoveCollectionContainer(CollectionContainer cc)
        {
            CollectionChangedEventManager.RemoveHandler(cc, OnContainedCollectionChanged);

#if DEBUG
            _hasRepeatedCollectionIsValid = false;
#endif
        }
コード例 #8
0
 private void UnregisterChangeHandler()
 {
     if (myChildObservationCount == 1)
     {
         CollectionChangedEventManager.RemoveHandler(Children, OnChildrenChanged);
     }
     myChildObservationCount--;
 }
コード例 #9
0
        /// <summary>
        /// Removes a weak event handler
        /// </summary>
        /// <param name="eventHandler"></param>
        public void RemoveHandler(IListener <NotifyCollectionChangedEventArgs> eventHandler)
        {
            if (eventHandler == null)
            {
                throw new ArgumentNullException(nameof(eventHandler), $"{nameof(eventHandler)} is null.");
            }

            m_CollectionChangeEventManager?.RemoveHandler(eventHandler);
        }
コード例 #10
0
ファイル: ObservableListView.cs プロジェクト: uzbekdev1/waf
 /// <summary>Override this method to free, release or reset any resources.</summary>
 /// <param name="disposing">if true then dispose unmanaged and managed resources; otherwise dispose only unmanaged resources.</param>
 protected override void OnDispose(bool disposing)
 {
     if (disposing)
     {
         if (originalObservableCollection != null)
         {
             CollectionChangedEventManager.RemoveHandler(originalObservableCollection, OriginalCollectionChanged);
         }
     }
     base.OnDispose(disposing);
 }
コード例 #11
0
        public static IObservable <ItemRemoved <T> > ObserveRemovedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemRemoved <T> >();

            var copy = new List <T>(list.Count + 8);

            foreach (var item in list)
            {
                copy.Add(item);
            }

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    copy.RemoveAt(e.OldStartingIndex);
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Replace:
                    copy[e.NewStartingIndex] = (T)e.NewItems[0];
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Move:
                    copy.RemoveAt(e.OldStartingIndex);
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = copy.Count - 1; i >= 0; --i)
                    {
                        subject.OnNext(new ItemRemoved <T>(copy[i], i));
                    }
                    copy.Clear();
                    foreach (var item in list)
                    {
                        copy.Add(item);
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
コード例 #12
0
        private static void TryCleanUpOldItem(Selector selector)
        {
            selector.SelectionChanged -= SelectorSelectionChanged;  // Remove a previously added event handler.

            var item = multiSelectorWithObservableList.FirstOrDefault(x => x.Item1.Selector == selector);

            if (item == null)
            {
                return;
            }

            multiSelectorWithObservableList.Remove(item);
            CollectionChangedEventManager.RemoveHandler(item.Item2, ListCollectionChanged);
        }
コード例 #13
0
    private void OnRangesChanged(IEnumerable <TextRangeToolTip> oldRanges, IEnumerable <TextRangeToolTip> newRanges)
    {
        var oldObservable = oldRanges as INotifyCollectionChanged;

        if (oldObservable != null)
        {
            CollectionChangedEventManager.RemoveHandler(oldObservable, this.OnRangesCollectionChanged);
        }
        var newObservable = newRanges as INotifyCollectionChanged;

        if (newObservable != null)
        {
            CollectionChangedEventManager.AddHandler(newObservable, this.OnRangesCollectionChanged);
        }
        this.UpdateToolTip();
    }
コード例 #14
0
        private void PolyLineCanvasItemPresenter_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var oldItem = e.OldValue as IPolyLineCanvasItem;

            if (oldItem != null)
            {
                CollectionChangedEventManager.RemoveHandler(oldItem.Points, CanvasItem_PointCollectionChanged);
            }
            var newItem = e.NewValue as IPolyLineCanvasItem;

            if (newItem != null)
            {
                CollectionChangedEventManager.AddHandler(newItem.Points, CanvasItem_PointCollectionChanged);
            }
            UpdatePathGeometry();
        }
コード例 #15
0
        private void UnregisterEventHandlers(IDockControl dataContext)
        {
            if (dataContext == null)
            {
                return;
            }

            // Detach from IDockControl.
            DockStrategy = null;
            PropertyChangedEventManager.RemoveHandler(dataContext, OnDockStrategyChanged, nameof(IDockControl.DockStrategy));
            PropertyChangedEventManager.RemoveHandler(dataContext, OnActiveItemChanged, nameof(IDockControl.ActiveDockTabItem));
            //PropertyChangedEventManager.RemoveHandler(dataContext, OnActivePaneChanged, nameof(IDockControl.ActiveDockTabPane));

            var collectionView = CollectionViewSource.GetDefaultView(dataContext.FloatWindows);

            CollectionChangedEventManager.RemoveHandler(collectionView, OnFloatWindowsChanged);
        }
コード例 #16
0
        public void ReplaceCollection(IReadOnlyList <T> collection)
        {
            if (_collection is INotifyCollectionChanged)
            {
                CollectionChangedEventManager.RemoveHandler(_collection as INotifyCollectionChanged, HandleCollectionChange);
            }

            _collection = collection;
            _watcherList?.Reset(_collection ?? Enumerable.Empty <T>());

            if (_collection is INotifyCollectionChanged)
            {
                CollectionChangedEventManager.AddHandler(_collection as INotifyCollectionChanged, HandleCollectionChange);
            }

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
コード例 #17
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }
            _isDisposed = true;

            if (_collection is INotifyCollectionChanged)
            {
                CollectionChangedEventManager.RemoveHandler(_collection as INotifyCollectionChanged, HandleCollectionChange);
                _watcherList?.Dispose();
                _watcherList = null;
                _collection  = null;
                ItemModified = null;
            }
        }
コード例 #18
0
 // Token: 0x06007551 RID: 30033 RVA: 0x00218620 File Offset: 0x00216820
 internal void Invalidate()
 {
     this.ClearAllCaches();
     if (this.List == null)
     {
         INotifyCollectionChanged notifyCollectionChanged = this.Enumerable as INotifyCollectionChanged;
         if (notifyCollectionChanged != null)
         {
             CollectionChangedEventManager.RemoveHandler(notifyCollectionChanged, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnCollectionChanged));
         }
     }
     this._enumerable = null;
     this.DisposeEnumerator(ref this._enumerator);
     this.DisposeEnumerator(ref this._changeTracker);
     this._collection     = null;
     this._list           = null;
     this._filterCallback = null;
 }
コード例 #19
0
 internal void Invalidate()
 {
     this.ClearAllCaches();
     if (this.List == null)
     {
         INotifyCollectionChanged source = this.Enumerable as INotifyCollectionChanged;
         if (source != null)
         {
             CollectionChangedEventManager.RemoveHandler(source, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnCollectionChanged));
         }
     }
     this._enumerable = (IEnumerable)null;
     this.DisposeEnumerator(ref this._enumerator);
     this.DisposeEnumerator(ref this._changeTracker);
     this._collection     = (ICollection)null;
     this._list           = (IList)null;
     this._filterCallback = (Predicate <object>)null;
 }
コード例 #20
0
ファイル: CollectionContainer.cs プロジェクト: beda2280/wpf-1
        // To prevent CollectionContainer memory leak:
        // HookUpToCollection() is called to start listening to CV only when
        // the Container is being used by a CompositeCollectionView.
        // When the last CCV stops using the container (or the CCV is GC'ed),
        // HookUpToCollection() is called to stop listening to its CV, so that
        // this container can be GC'ed if no one else is holding on to it.

        // unhook old collection/view and hook up new collection/view
        private void HookUpToCollection(IEnumerable newCollection, bool shouldRaiseChangeEvent)
        {
            // clear cached helper
            _viewList = null;

            // unhook from the old collection view
            if (View != null)
            {
                CollectionChangedEventManager.RemoveHandler(View, OnCollectionChanged);

                if (_traceLog != null)
                {
                    _traceLog.Add("Unsubscribe to CollectionChange from {0}",
                                  TraceLog.IdFor(View));
                }
            }

            // change to the new view
            if (newCollection != null)
            {
                _view = CollectionViewSource.GetDefaultCollectionView(newCollection, this);
            }
            else
            {
                _view = null;
            }

            // hook up to the new collection view
            if (View != null)
            {
                CollectionChangedEventManager.AddHandler(View, OnCollectionChanged);

                if (_traceLog != null)
                {
                    _traceLog.Add("Subscribe to CollectionChange from {0}", TraceLog.IdFor(View));
                }
            }

            if (shouldRaiseChangeEvent) // it's as if this were a refresh of the container's collection
            {
                OnContainedCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
コード例 #21
0
        private static void OnSourceErrorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Scope.GetNode(d) is InputNode node)
            {
                if (e.OldValue is ReadOnlyObservableCollection <ValidationError> oldErrors &&
                    !ReferenceEquals(oldErrors, ErrorCollection.EmptyValidationErrors))
                {
                    CollectionChangedEventManager.RemoveHandler(oldErrors, node.OnSourceErrorsChanged);
                    node.ErrorCollection.Remove(oldErrors);
                }

                if (e.NewValue is ReadOnlyObservableCollection <ValidationError> newErrors &&
                    !ReferenceEquals(newErrors, ErrorCollection.EmptyValidationErrors))
                {
                    CollectionChangedEventManager.AddHandler(newErrors, node.OnSourceErrorsChanged);
                    node.ErrorCollection.Add(newErrors);
                }
            }
        }
コード例 #22
0
ファイル: IndexedEnumerable.cs プロジェクト: beda2280/wpf-1
        internal void Invalidate()
        {
            ClearAllCaches();

            // only track changes if source collection isn't already of type IList
            if (List == null)
            {
                INotifyCollectionChanged icc = Enumerable as INotifyCollectionChanged;
                if (icc != null)
                {
                    CollectionChangedEventManager.RemoveHandler(icc, OnCollectionChanged);
                }
            }

            _enumerable = null;
            DisposeEnumerator(ref _enumerator);
            DisposeEnumerator(ref _changeTracker);
            _collection     = null;
            _list           = null;
            _filterCallback = null;
        }
コード例 #23
0
 // Token: 0x06001A5F RID: 6751 RVA: 0x0007D89C File Offset: 0x0007BA9C
 private void HookUpToCollection(IEnumerable newCollection, bool shouldRaiseChangeEvent)
 {
     this._viewList = null;
     if (this.View != null)
     {
         CollectionChangedEventManager.RemoveHandler(this.View, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnCollectionChanged));
         if (this._traceLog != null)
         {
             this._traceLog.Add("Unsubscribe to CollectionChange from {0}", new object[]
             {
                 TraceLog.IdFor(this.View)
             });
         }
     }
     if (newCollection != null)
     {
         this._view = CollectionViewSource.GetDefaultCollectionView(newCollection, this, null);
     }
     else
     {
         this._view = null;
     }
     if (this.View != null)
     {
         CollectionChangedEventManager.AddHandler(this.View, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnCollectionChanged));
         if (this._traceLog != null)
         {
             this._traceLog.Add("Subscribe to CollectionChange from {0}", new object[]
             {
                 TraceLog.IdFor(this.View)
             });
         }
     }
     if (shouldRaiseChangeEvent)
     {
         this.OnContainedCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
     }
 }
コード例 #24
0
        public static IObservable <IReadOnlyList <T> > ObserveAll <T>(this IActiveList <T> list)
        {
            var subject = new Subject <IReadOnlyList <T> >();

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                var count = list.Count;

                var array = new T[count];
                for (int i = 0; i < count; ++i)
                {
                    array[i] = list[i];
                }

                subject.OnNext(array);
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
コード例 #25
0
ファイル: IndexedEnumerable.cs プロジェクト: algel/WpfTools
        internal void Invalidate()
        {
            ClearAllCaches();

            // only track changes if source collection isn't already of type IList
            if (List == null)
            {
                if (Enumerable is INotifyCollectionChanged icc)
                {
#if NET45
                    CollectionChangedEventManager.RemoveHandler(icc, OnCollectionChanged);
#elif NET40
                    CollectionChangedEventManager.RemoveListener(icc, this);
#endif
                }
            }

            _enumerable = null;
            DisposeEnumerator(ref _enumerator);
            DisposeEnumerator(ref _changeTracker);
            _collection     = null;
            _list           = null;
            _filterCallback = null;
        }
コード例 #26
0
 // Token: 0x06001B49 RID: 6985 RVA: 0x00080688 File Offset: 0x0007E888
 private void RemoveCollectionContainer(CollectionContainer cc)
 {
     CollectionChangedEventManager.RemoveHandler(cc, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnContainedCollectionChanged));
 }
コード例 #27
0
 public void RemoveHandler(INotifyCollectionChanged source, EventHandler <NotifyCollectionChangedEventArgs> handler) => CollectionChangedEventManager.RemoveHandler(source, handler);
コード例 #28
0
 public void Shutdown()
 {
     CollectionChangedEventManager.RemoveHandler(LogViewModel.AppliedFilterList, OnFilterChanged);
 }
コード例 #29
0
 public static void RemoveHandler(this INotifyCollectionChanged source, EventHandler <NotifyCollectionChangedEventArgs> handler)
 {
     CollectionChangedEventManager.RemoveHandler(source, handler);
 }