Пример #1
0
 protected void RemoveDependencySource(string name, INotifyCollectionChanged source)
 {
     ArgumentValidation.NotNullOrEmpty <char>(name, "name");
     ArgumentValidation.NotNull(source, "source");
     CollectionChangedEventManager.RemoveListener(source, this);
     _collectionSources.Value.Remove(source);
 }
        /// <summary>
        /// Assigns an enumeration that serves as a source for this list.
        /// </summary>
        /// <param name="sourceList">The new source, or <see langword="null"/> if the current list should manage its own items.</param>
        internal void SetSourceList(System.Collections.IEnumerable sourceList)
        {
            if (this.sourceList == sourceList)
            {
                return;
            }

            var observable = this.sourceList as INotifyCollectionChanged;

            if (observable != null)
            {
                CollectionChangedEventManager.RemoveListener(observable, this.sourceListChangeListener);
            }

            lockForSourceList = false;
            this.Clear();
            this.sourceList = sourceList;

            if (sourceList != null)
            {
                ReloadSourceList();

                observable = this.sourceList as INotifyCollectionChanged;
                if (observable != null)
                {
                    CollectionChangedEventManager.AddListener(observable, this.sourceListChangeListener);
                }
            }
        }
Пример #3
0
        public virtual bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            var ccea = (NotifyCollectionChangedEventArgs)e;

            if (ReferenceEquals(sender, this.Source))
            {
                var oldItems = ccea.OldItems;
                if (oldItems != null)
                {
                    foreach (var incc in oldItems.OfType <INotifyCollectionChanged>())
                    {
                        CollectionChangedEventManager.RemoveListener(incc, this);
                    }
                }

                var newItems = ccea.NewItems;
                if (newItems != null)
                {
                    foreach (var incc in newItems.OfType <INotifyCollectionChanged>())
                    {
                        CollectionChangedEventManager.AddListener(incc, this);
                    }
                }
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Provides derived classes an opportunity to handle changes to the <see cref="Appointments"/>.
        /// </summary>
        protected virtual void OnAppointmentsChanged(DependencyPropertyChangedEventArgs args)
        {
            var oldAppointments = args.OldValue as INotifyCollectionChanged;

            if (oldAppointments != null)
            {
                CollectionChangedEventManager.RemoveListener(oldAppointments, this);
            }

            if (args.OldValue != null)
            {
                foreach (IAppointment unhook in (IList)args.OldValue)
                {
                    this.UnHookNewAppointment(unhook);
                }
            }

            var newAppointments = args.NewValue as INotifyCollectionChanged;

            if (newAppointments != null)
            {
                CollectionChangedEventManager.AddListener(newAppointments, this);
            }

            if (args.NewValue != null)
            {
                foreach (IAppointment hook in (IList)args.NewValue)
                {
                    this.HookNewAppointment(hook);
                }
            }
        }
 /// <summary>
 /// Called whenever one of the inner collection changed.
 /// </summary>
 /// <param name="managerType">Type of the manager we subscribed to.</param>
 /// <param name="sender">The collection that sent the event.</param>
 /// <param name="e">Information about the event.</param>
 /// <returns>True if was able to perform the required operation.</returns>
 /// <remarks><see cref="IWeakEventListener"/> implementation.</remarks>
 public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
 {
     if (TargetObject != null && TargetProperty != null)
     {
         if (managerType == typeof(CollectionChangedEventManager))
         {
             // Update only if collection change event args matches the allowed actions for notification:
             if (e is NotifyCollectionChangedEventArgs collectionargs && ActionsToNotify.HasFlag(collectionargs.Action))
             {
                 // Update binding target when collection changed:
                 if (updateTargetAction != null)
                 {
                     if (Application.Current.Dispatcher.CheckAccess())
                     {
                         updateTargetAction.Invoke();
                     }
                     else
                     {
                         Application.Current.Dispatcher.BeginInvoke(updateTargetAction);
                     }
                 }
             }
         }
     }
     else if (sender is INotifyCollectionChanged collection)
     {
         CollectionChangedEventManager.RemoveListener(collection, this); // our binding expression is not used anymore, we can shut listening down.
     }
     return(true);                                                       // always return true otherwise ugly exception happen in the framework core.
 }
        private void CleanHeadersFootersNotification(HeadersFootersGeneratorNode node)
        {
            var collection = node.Items as INotifyCollectionChanged;

            if (collection == null)
            {
                return;
            }

            try
            {
                var nodeList = m_headersFootersMapping[collection];
                nodeList.Remove(node);

                if (nodeList.Count == 0)
                {
                    CollectionChangedEventManager.RemoveListener(collection, this);
                    m_headersFootersMapping.Remove(collection);
                }
            }
            catch (Exception e)
            {
                throw new DataGridInternalException(e.Message, e, this.DataGridControl);
            }
        }
 private void UnregisterNodeCollectionChanged(INotifyCollectionChanged source)
 {
     if (m_nodesCollectionChangedEventHandlers.Remove(source))
     {
         CollectionChangedEventManager.RemoveListener(source, this);
     }
 }
        protected override void Uninitialize()
        {
            BindingOperations.ClearBinding(this,
                                           TableViewColumnVirtualizationManager.FixedColumnCountProperty);

            BindingOperations.ClearBinding(this,
                                           TableViewColumnVirtualizationManager.IsVirtualizingProperty);

            BindingOperations.ClearBinding(this,
                                           TableViewColumnVirtualizationManager.FirstColumnCompensationOffsetProperty);


            if (m_scrollViewer != null)
            {
                m_scrollViewer.ScrollChanged -= new ScrollChangedEventHandler(this.ScrollViewer_ScrollChanged);
            }

            ColumnActualWidthEventManager.RemoveListener(this.DataGridContext.Columns, this);
            DataGridControlTemplateChangedEventManager.RemoveListener(this.DataGridContext.DataGridControl, this);

            CollectionChangedEventManager.RemoveListener(this.DataGridContext.Items.SortDescriptions, this);
            CollectionChangedEventManager.RemoveListener(this.DataGridContext.Items.GroupDescriptions, this);


            base.Uninitialize();
        }
        private static void OnDataGridContextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            GroupLevelIndicatorPane self = sender as GroupLevelIndicatorPane;

            if (self != null)
            {
                DataGridContext dataGridContext = e.OldValue as DataGridContext;

                //unregister to the old contexts Collection GroupDescriptions Changed event
                if (dataGridContext != null)
                {
                    CollectionChangedEventManager.RemoveListener(dataGridContext.Items.GroupDescriptions, self);
                }

                dataGridContext = e.NewValue as DataGridContext;

                //register to the new contexts Collection GroupDescriptions Changed event
                if (dataGridContext != null)
                {
                    CollectionChangedEventManager.AddListener(dataGridContext.Items.GroupDescriptions, self);
                    self.PrepareDefaultStyleKey(dataGridContext.DataGridControl.GetView());
                }

                self.InvalidateMeasure();
            }
        }
Пример #10
0
 /// <summary>
 /// Stops listening for change events.
 /// </summary>
 /// <param name="list">The list to stop listening to.</param>
 protected void StopListeningForChangeEvents(IList list)
 {
     if (list is INotifyCollectionChanged)
     {
         CollectionChangedEventManager.RemoveListener((INotifyCollectionChanged)list, this);
     }
 }
Пример #11
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // Cleanup managed resources
                    CollectionChangedEventManager.RemoveListener(this.sourceCollection, this);

                    if (this.teardown != null)
                    {
                        foreach (var target in this.Items)
                        {
                            this.teardown(target);
                        }
                    }

                    this.Items.Clear();
                }

                // Cleanup unmanaged resources

                // Mark the object as disposed
                this.disposed = true;
            }
        }
Пример #12
0
        /// <summary>
        ///     Removes the weak event listener for a CollectionChanged event.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="handler">The event handler.</param>
        /// <exception cref="T:System.ArgumentNullException">source must not be <c>null</c>.</exception>
        /// <exception cref="T:System.ArgumentNullException">handler must not be <c>null</c>.</exception>
        protected void RemoveWeakEventListener(INotifyCollectionChanged source,
                                               NotifyCollectionChangedEventHandler handler)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            CollectionChangedEventListener changedEventListener = collectionChangedListeners.LastOrDefault(l =>
            {
                if (l.Source == source)
                {
                    return(l.Handler == handler);
                }
                return(false);
            });

            if (changedEventListener == null)
            {
                return;
            }
            collectionChangedListeners.Remove(changedEventListener);
            CollectionChangedEventManager.RemoveListener(source, changedEventListener);
        }
        /// <summary>
        /// Handles a change to the Columns property.
        /// </summary>
        /// <param name="dependencyObject">The DependancyObject that owns the property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The DependencyProperty that has changed.</param>
        static void OnColumnsPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // The listener is the object that owns the Columns property.
            ColumnViewRowPresenterBase columnViewRowPresenterBase = dependencyObject as ColumnViewRowPresenterBase;

            // This will disconnect the old listener from getting changes to the columns.
            ColumnViewColumnCollection oldCollection = dependencyPropertyChangedEventArgs.OldValue as ColumnViewColumnCollection;

            if (oldCollection != null)
            {
                // This will disconnect the RowPresenter from changes made to the old column collection.
                CollectionChangedEventManager.RemoveListener(oldCollection, columnViewRowPresenterBase);

                // This will clear out any items from the old collection.  This is preferrable to a collection 'Reset' because we can provide the columns that have
                // gone out of scope which might not be available any other way.
                columnViewRowPresenterBase.OnColumnCollectionChanged(
                    columnViewRowPresenterBase,
                    new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldCollection));
            }

            // This will connect the new listener to get changes to the columns.
            ColumnViewColumnCollection newCollection = dependencyPropertyChangedEventArgs.NewValue as ColumnViewColumnCollection;

            if (newCollection != null)
            {
                // This will connect the RowPresenter to the collection of columns so that any changes made to the column set is reflected in the arrangement of
                // cells in the view.
                CollectionChangedEventManager.AddListener(newCollection, columnViewRowPresenterBase);

                // This will syncrhonize the view to the new column set.
                columnViewRowPresenterBase.OnColumnCollectionChanged(
                    columnViewRowPresenterBase,
                    new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newCollection));
            }
        }
Пример #14
0
        protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            base.OnItemsSourceChanged(oldValue, newValue);

            var oldCollection = oldValue as INotifyCollectionChanged;
            var newCollection = newValue as INotifyCollectionChanged;

            if (oldCollection != null)
            {
                CollectionChangedEventManager.RemoveListener(oldCollection, this);
            }

            if (newCollection != null)
            {
                CollectionChangedEventManager.AddListener(newCollection, this);
            }

            if (!this.IsInitialized)
            {
                return;
            }

            if (!VirtualizingStackPanel.GetIsVirtualizing(this) ||
                (VirtualizingStackPanel.GetIsVirtualizing(this) && (newValue != null)))
            {
                this.RemoveUnavailableSelectedItems();
            }

            this.UpdateSelectedMemberPathValuesBindings();
            this.UpdateValueMemberPathValuesBindings();
        }
Пример #15
0
        private static void OnErrorsProxyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var node = (ErrorNode)d.GetValue(Scope.ErrorsProperty);

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

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

            if (oldValue != null)
            {
                CollectionChangedEventManager.RemoveListener(oldValue, node);
            }

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

            if (newValue != null)
            {
                CollectionChangedEventManager.AddListener(newValue, node);
            }

            node.RefreshErrors();
            BubbleRoute.Notify(node);
        }
Пример #16
0
 internal void ReleaseEvents()
 {
     if (_innerListListener is not null)
     {
         CollectionChangedEventManager.RemoveListener((INotifyCollectionChanged)_innerList, _innerListListener);
         _innerListListener = null;
     }
 }
Пример #17
0
 protected void StopListeningForChangeEvents(IList list)
 {
     if (!(list is INotifyCollectionChanged))
     {
         return;
     }
     CollectionChangedEventManager.RemoveListener(list as INotifyCollectionChanged, (IWeakEventListener)this);
 }
Пример #18
0
        protected override void RemoveItem(int index)
        {
            if (this[index] is INotifyCollectionChanged observablePolygon)
            {
                CollectionChangedEventManager.RemoveListener(observablePolygon, this);
            }

            base.RemoveItem(index);
        }
Пример #19
0
        protected override void ClearItems()
        {
            foreach (var observablePolygon in this.OfType <INotifyCollectionChanged>())
            {
                CollectionChangedEventManager.RemoveListener(observablePolygon, this);
            }

            base.ClearItems();
        }
Пример #20
0
        /// <summary>
        ///     Stops listening for change events.
        /// </summary>
        /// <param name="list">The list to stop listening to.</param>
        protected void StopListeningForChangeEvents(IList list)
        {
            var source = list as INotifyCollectionChanged;

            if (source != null)
            {
                CollectionChangedEventManager.RemoveListener(source, this);
            }
        }
Пример #21
0
        /// <inheritdoc />
        protected override void RemoveItem(int index)
        {
            WallpaperCategory category = this[index];

            base.RemoveItem(index);
            CollectionChangedEventManager.RemoveListener(category, this);

            this.OnPropertyChanged("AllWallpapersCount");
        }
Пример #22
0
        protected override void SetItem(int index, IEnumerable <Location> polygon)
        {
            if (this[index] is INotifyCollectionChanged observablePolygon)
            {
                CollectionChangedEventManager.RemoveListener(observablePolygon, this);
            }

            base.SetItem(index, polygon);
        }
Пример #23
0
            private void UnregisterCollectionChanged(INotifyCollectionChanged collection)
            {
                if (collection == null)
                {
                    return;
                }

                CollectionChangedEventManager.RemoveListener(collection, this);
            }
        private void Unsubscribe(ICollection collection)
        {
            var notifierCollection = collection as INotifyCollectionChanged;

            if (notifierCollection != null)
            {
                CollectionChangedEventManager.RemoveListener(notifierCollection, this);
            }
        }
Пример #25
0
        /// <summary>
        /// Stops listening for change events.
        /// </summary>
        /// <param name="list">The list to stop listening to.</param>
        protected void StopListeningForChangeEvents(IList list)
        {
            var notifyingList = list as INotifyCollectionChanged;

            if (list != null)
            {
                CollectionChangedEventManager.RemoveListener(notifyingList, this);
            }
        }
Пример #26
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            INotifyCollectionChanged source = GetSource();

            if (source != null)
            {
                CollectionChangedEventManager.RemoveListener(source, this);
            }
            CollectionChanged = null;
        }
Пример #27
0
        protected void UnlinkVirtualListAndCollectionViewGroup(VirtualList virtualList)
        {
            DataGridVirtualizingCollectionViewGroupBase collectionViewGroup = null;

            if (m_virtualListVSCollectionViewGroupDictionary.TryGetValue(virtualList, out collectionViewGroup))
            {
                CollectionChangedEventManager.RemoveListener(virtualList, collectionViewGroup);
                m_virtualListVSCollectionViewGroupDictionary.Remove(virtualList);
            }
        }
Пример #28
0
        protected override void RemoveItem(int index)
        {
            var observablePolygon = this[index] as INotifyCollectionChanged;

            if (observablePolygon != null)
            {
                CollectionChangedEventManager.RemoveListener(observablePolygon, this);
            }

            base.RemoveItem(index);
        }
        internal void UnregisterAllAutoFilterValuesChangedEvent()
        {
            foreach (INotifyCollectionChanged autoFilterValues in m_registeredAutoFilterValuesToFieldNames.Keys)
            {
                CollectionChangedEventManager.RemoveListener(autoFilterValues, this);
            }

            m_registeredAutoFilterValuesToFieldNames.Clear();
            m_registeredFieldNamesToAutoFilterValues.Clear();
            this.DetailDescriptionAutoFilterValuesChanged = null;
        }
Пример #30
0
        private void UnAdoptSourceCollection()
        {
            var notifyChangedCollection = this.sourceCollection as INotifyCollectionChanged;

            if (notifyChangedCollection != null)
            {
                CollectionChangedEventManager.RemoveListener(notifyChangedCollection, this);
            }

            this.sourceCollection = null;
        }