예제 #1
0
        // 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));
            }
        }
 // 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));
     }
 }