/// <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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, IList changedItems, int startingIndex)
 {
     if ((action != MVVMNotifyCollectionChangedAction.Add) && (action != MVVMNotifyCollectionChangedAction.Remove) &&
         (action != MVVMNotifyCollectionChangedAction.Reset))
     {
         throw new Exception("action");
     }
     if (action == MVVMNotifyCollectionChangedAction.Reset)
     {
         if (changedItems != null)
         {
             throw new Exception("action");
         }
         if (startingIndex != -1)
         {
             throw new Exception("action");
         }
         InitializeAdd(action, null, -1);
     }
     else
     {
         if (changedItems == null)
         {
             throw new Exception("action");
         }
         if (startingIndex < -1)
         {
             throw new Exception("action");
         }
         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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, object changedItem, int index)
        {
            if ((action != MVVMNotifyCollectionChangedAction.Add) && (action != MVVMNotifyCollectionChangedAction.Remove) &&
                (action != MVVMNotifyCollectionChangedAction.Reset))
            {
                throw new Exception("action");
            }

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

                InitializeAdd(action, null, -1);
            }
            else
            {
                InitializeAddOrRemove(action, new object[] { changedItem }, index);
            }
        }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item change.
        /// </summary>
        /// <param name="action">The action that caused the event.</param>
        /// <param name="changedItems">The items affected by the change.</param>
        public MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, IList changedItems)
        {
            if ((action != MVVMNotifyCollectionChangedAction.Add) && (action != MVVMNotifyCollectionChangedAction.Remove) &&
                (action != MVVMNotifyCollectionChangedAction.Reset))
            {
                throw new Exception("action");
            }
            if (action == MVVMNotifyCollectionChangedAction.Reset)
            {
                if (changedItems != null)
                {
                    throw new Exception("action");
                }
                InitializeAdd(action, null, -1);
            }
            else
            {
                if (changedItems == null)
                {
                    throw new ArgumentNullException("changedItems");
                }

                InitializeAddOrRemove(action, changedItems, -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>
 public MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, object newItem, object oldItem)
 {
     if (action != MVVMNotifyCollectionChangedAction.Replace)
     {
         throw new Exception("action");
     }
     InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, -1, -1);
 }
        //------------------------------------------------------
        //
        //  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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action)
        {
            if (action != MVVMNotifyCollectionChangedAction.Reset)
            {
                throw new Exception("action");
            }

            InitializeAdd(action, null, -1);
        }
 /// <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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, IList changedItems, int index, int oldIndex)
 {
     if (action != MVVMNotifyCollectionChangedAction.Move)
     {
         throw new Exception("action");
     }
     if (index < 0)
     {
         throw new Exception("action");
     }
     InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
 }
        private void InitializeAdd(MVVMNotifyCollectionChangedAction action, IList newItems, int newStartingIndex)
        {
            _action = action;
#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                _newItems = newItems;
            }
            else
#endif // !FEATURE_LEGACYNETCF
            {
                _newItems = (newItems == null) ? null : ArrayList.ReadOnly(newItems);
            }
            _newStartingIndex = newStartingIndex;
        }
 private void InitializeAddOrRemove(MVVMNotifyCollectionChangedAction action, IList changedItems, int startingIndex)
 {
     if (action == MVVMNotifyCollectionChangedAction.Add)
     {
         InitializeAdd(action, changedItems, startingIndex);
     }
     else if (action == MVVMNotifyCollectionChangedAction.Remove)
     {
         InitializeRemove(action, changedItems, startingIndex);
     }
     else
     {
         //Contract.Assert (false, String.Format ("Unsupported action: {0}", action.ToString ()));
     }
 }
        /// <summary>
        /// Construct a NotifyCollectionChangedEventArgs with given fields (no validation). Used by WinRT marshaling.
        /// </summary>
        internal MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex)
        {
            _action = action;
#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                _newItems = newItems;
            }
            else
#endif
            {
                _newItems = (newItems == null) ? null : ArrayList.ReadOnly(newItems);
            }
            _oldItems         = (oldItems == null) ? null : ArrayList.ReadOnly(oldItems);
            _newStartingIndex = newIndex;
            _oldStartingIndex = oldIndex;
        }
        /// <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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, IList newItems, IList oldItems, int startingIndex)
        {
            if (action != MVVMNotifyCollectionChangedAction.Replace)
            {
                throw new Exception("action");
            }
            if (newItems == null)
            {
                throw new ArgumentNullException("newItems");
            }
            if (oldItems == null)
            {
                throw new ArgumentNullException("oldItems");
            }

            InitializeMoveOrReplace(action, newItems, oldItems, startingIndex, startingIndex);
        }
        /// <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 MVVMNotifyCollectionChangedEventArgs(MVVMNotifyCollectionChangedAction action, object newItem, object oldItem, int index)
        {
            if (action != MVVMNotifyCollectionChangedAction.Replace)
            {
                throw new Exception("action");
            }
            int oldStartingIndex = index;

#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                // Dev11 444113 quirk:
                // This is a "Replace" so the old and new index should both be set to the index passed in however
                // NetCF on Mango incorrectly leaves OldStartingIndex at -1 and Mango apps depend on this behavior.
                oldStartingIndex = -1;
            }
#endif
            InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, index, oldStartingIndex);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Helper to raise CollectionChanged event to any listeners
 /// </summary>
 private void OnCollectionChanged(MVVMNotifyCollectionChangedAction action, object oldItem, object newItem, int index)
 {
     OnCollectionChanged(new MVVMNotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
 }
 private void InitializeMoveOrReplace(MVVMNotifyCollectionChangedAction action, IList newItems, IList oldItems, int startingIndex, int oldStartingIndex)
 {
     InitializeAdd(action, newItems, startingIndex);
     InitializeRemove(action, oldItems, oldStartingIndex);
 }
 private void InitializeRemove(MVVMNotifyCollectionChangedAction action, IList oldItems, int oldStartingIndex)
 {
     _action           = action;
     _oldItems         = (oldItems == null) ? null : ArrayList.ReadOnly(oldItems);
     _oldStartingIndex = oldStartingIndex;
 }