The notify list changed event args.
Inheritance: System.ComponentModel.ListChangedEventArgs
Exemple #1
0
        /// <summary>
        /// Raises the <see cref="BindingList{T}.ListChanged" /> event, but also makes sure the event is dispatched to the UI thread.
        /// </summary>
        /// <param name="e">The <see cref="ListChangedEventArgs" /> instance containing the event data.</param>
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            // Convert args if needed
            if (!(e is NotifyListChangedEventArgs))
            {
                if (e.NewIndex >= 0 && e.OldIndex >= 0)
                {
                    e = new NotifyListChangedEventArgs(e.ListChangedType,
                                                       e.NewIndex,
                                                       e.NewIndex >= 0 ? this[e.NewIndex] : default(T),
                                                       e.OldIndex,
                                                       e.OldIndex >= 0 ? this[e.OldIndex] : default(T));
                }
                else
                {
                    e = new NotifyListChangedEventArgs(e.ListChangedType,
                                                       e.NewIndex,
                                                       e.NewIndex >= 0 ? this[e.NewIndex] : default(T),
                                                       e.PropertyDescriptor);
                }
            }

            if (AutomaticallyDispatchChangeNotifications)
            {
                _dispatcherService.BeginInvokeIfRequired(() => base.OnListChanged(e));
            }
            else
            {
                base.OnListChanged(e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Notifies external classes of property changes.
        /// </summary>
        protected void NotifyChanges()
        {
            Action action = () =>
            {
                // Create event args
                ListChangedEventArgs eventArgs = null;
                if (_suspensionContext != null && _suspensionContext.Mode == SuspensionMode.Adding)
                {
                    if (_suspensionContext.NewItems.Count != 0)
                    {
                        eventArgs = new NotifyRangedListChangedEventArgs(NotifyRangedListChangedAction.Add, _suspensionContext.NewItems, _suspensionContext.NewItemIndices);
                    }
                }
                else if (_suspensionContext != null && _suspensionContext.Mode == SuspensionMode.Removing)
                {
                    if (_suspensionContext.OldItems.Count != 0)
                    {
                        eventArgs = new NotifyRangedListChangedEventArgs(NotifyRangedListChangedAction.Remove, _suspensionContext.OldItems, _suspensionContext.OldItemIndices);
                    }
                }
                else
                {
                    eventArgs = new NotifyListChangedEventArgs(ListChangedType.Reset);
                }

                // Fire events
                if (eventArgs != null)
                {
                    OnListChanged(eventArgs);
                }
            };

            if (AutomaticallyDispatchChangeNotifications)
            {
                _dispatcherService.BeginInvokeIfRequired(action);
            }
            else
            {
                action();
            }
        }