/// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item change (or a reset).
        /// </summary>
        /// <param name="action">The action that caused the event.</param>
        /// <param name="changedItems">The items affected by the change.</param>
        /// <param name="startingIndex">The index where the change occurred.</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, IList changedItems, int startingIndex)
        {
            if ((action != NotifyCollectionChangedActionEx.Add) && (action != NotifyCollectionChangedActionEx.Remove) &&
                (action != NotifyCollectionChangedActionEx.Reset))
            {
                throw new ArgumentException("action");
            }

            if (action == NotifyCollectionChangedActionEx.Reset)
            {
                if (changedItems != null)
                {
                    throw new ArgumentException("action");
                }
                if (startingIndex != -1)
                {
                    throw new ArgumentException("action");
                }

                InitializeAdd(action, null, -1);
            }
            else
            {
                if (changedItems == null)
                {
                    throw new ArgumentNullException("changedItems");
                }
                if (startingIndex < -1)
                {
                    throw new ArgumentException("startingIndex");
                }

                InitializeAddOrRemove(action, changedItems, startingIndex);
            }
        }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a one-item change.
        /// </summary>
        /// <param name="action">The action that caused the event.</param>
        /// <param name="changedItem">The item affected by the change.</param>
        /// <param name="index">The index where the change occurred.</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, object changedItem, int index)
        {
            if ((action != NotifyCollectionChangedActionEx.Add) && (action != NotifyCollectionChangedActionEx.Remove) &&
                (action != NotifyCollectionChangedActionEx.Reset))
            {
                throw new ArgumentException("action");
            }

            if (action == NotifyCollectionChangedActionEx.Reset)
            {
                if (changedItem != null)
                {
                    throw new ArgumentException("action");
                }
                if (index != -1)
                {
                    throw new ArgumentException("action");
                }

                InitializeAdd(action, null, -1);
            }
            else
            {
                InitializeAddOrRemove(action, new object[] { changedItem }, index);
            }
        }
Example #3
0
 private void OnCollectionChanged(NotifyCollectionChangedActionEx action, IList newItems)
 {
     OnPropertyChanged();
     if (CollectionChanged != null)
     {
         CollectionChanged(this, new NotifyCollectionChangedEventArgsEx(action, newItems));
     }
 }
Example #4
0
 private void OnCollectionChanged(NotifyCollectionChangedActionEx action, KeyValuePair <TKey, TValue> newItem, KeyValuePair <TKey, TValue> oldItem)
 {
     OnPropertyChanged();
     if (CollectionChanged != null)
     {
         CollectionChanged(this, new NotifyCollectionChangedEventArgsEx(action, newItem, oldItem));
     }
 }
 /// <summary>
 /// Construct a NotifyCollectionChangedEventArgs with given fields (no validation). Used by WinRT marshaling.
 /// </summary>
 internal NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, IList newItems, IList oldItems, int newIndex, int oldIndex)
 {
     _action           = action;
     _newItems         = (newItems == null) ? null : new ReadOnlyList(newItems);
     _oldItems         = (oldItems == null) ? null : new ReadOnlyList(oldItems);
     _newStartingIndex = newIndex;
     _oldStartingIndex = oldIndex;
 }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a reset change.
        /// </summary>
        /// <param name="action">The action that caused the event (must be Reset).</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action)
        {
            if (action != NotifyCollectionChangedActionEx.Reset)
            {
                throw new ArgumentException("action");
            }

            InitializeAdd(action, null, -1);
        }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a one-item Replace event.
        /// </summary>
        /// <param name="action">Can only be a Replace action.</param>
        /// <param name="newItem">The new item replacing the original item.</param>
        /// <param name="oldItem">The original item that is replaced.</param>
        /// <param name="index">The index of the item being replaced.</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, object newItem, object oldItem, int index)
        {
            if (action != NotifyCollectionChangedActionEx.Replace)
            {
                throw new ArgumentException("action");
            }

            InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, index, index);
        }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item Move event.
        /// </summary>
        /// <param name="action">The action that caused the event.</param>
        /// <param name="changedItems">The items affected by the change.</param>
        /// <param name="index">The new index for the changed items.</param>
        /// <param name="oldIndex">The old index for the changed items.</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, IList changedItems, int index, int oldIndex)
        {
            if (action != NotifyCollectionChangedActionEx.Move)
            {
                throw new ArgumentException("action");
            }
            if (index < 0)
            {
                throw new ArgumentException("index");
            }

            InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
        }
 private void InitializeAddOrRemove(NotifyCollectionChangedActionEx action, IList changedItems, int startingIndex)
 {
     if (action == NotifyCollectionChangedActionEx.Add)
     {
         InitializeAdd(action, changedItems, startingIndex);
     }
     else if (action == NotifyCollectionChangedActionEx.Remove)
     {
         InitializeRemove(action, changedItems, startingIndex);
     }
     else
     {
         Debug.Assert(false, String.Format("Unsupported action: {0}", action.ToString()));
     }
 }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item Replace event.
        /// </summary>
        /// <param name="action">Can only be a Replace action.</param>
        /// <param name="newItems">The new items replacing the original items.</param>
        /// <param name="oldItems">The original items that are replaced.</param>
        /// <param name="startingIndex">The starting index of the items being replaced.</param>
        public NotifyCollectionChangedEventArgsEx(NotifyCollectionChangedActionEx action, IList newItems, IList oldItems, int startingIndex)
        {
            if (action != NotifyCollectionChangedActionEx.Replace)
            {
                throw new ArgumentException("action");
            }
            if (newItems == null)
            {
                throw new ArgumentNullException("newItems");
            }
            if (oldItems == null)
            {
                throw new ArgumentNullException("oldItems");
            }

            InitializeMoveOrReplace(action, newItems, oldItems, startingIndex, startingIndex);
        }
 private void InitializeMoveOrReplace(NotifyCollectionChangedActionEx action, IList newItems, IList oldItems, int startingIndex, int oldStartingIndex)
 {
     InitializeAdd(action, newItems, startingIndex);
     InitializeRemove(action, oldItems, oldStartingIndex);
 }
 private void InitializeRemove(NotifyCollectionChangedActionEx action, IList oldItems, int oldStartingIndex)
 {
     _action           = action;
     _oldItems         = (oldItems == null) ? null : new ReadOnlyList(oldItems);
     _oldStartingIndex = oldStartingIndex;
 }
 private void InitializeAdd(NotifyCollectionChangedActionEx action, IList newItems, int newStartingIndex)
 {
     _action           = action;
     _newItems         = (newItems == null) ? null : new ReadOnlyList(newItems);
     _newStartingIndex = newStartingIndex;
 }