Exemplo n.º 1
0
        private void InsertItem(TKey key, TValue value, int index)
        {
            if (RaiseListChangedEvents)
            {
                var args = new ListChgEventArgs <TValue>(this, ListChg.ItemPreAdd, index, value);
                OnListChanging(args);
                if (args.Cancel)
                {
                    return;
                }

                // Allow PreAdd to modify 'item' and 'index'
                value = args.Item;
                index = args.Index;
            }

            InsertItemCore(key, value, index);

            if (RaiseListChangedEvents)
            {
                OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.ItemAdded, index, value));
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, value));
            }
        }
Exemplo n.º 2
0
 private void ResetItem(TKey key, int index)
 {
     if (RaiseListChangedEvents)
     {
         var args = new ListChgEventArgs <TValue>(this, ListChg.ItemPreReset, index, m_dict[key]);
         OnListChanging(args);
         if (args.Cancel)
         {
             return;
         }
     }
     if (RaiseListChangedEvents)
     {
         OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.ItemReset, index, m_dict[key]));
         OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
     }
 }
Exemplo n.º 3
0
 public void ResetBindings()
 {
     if (RaiseListChangedEvents)
     {
         var args = new ListChgEventArgs <TValue>(this, ListChg.PreReset, -1, default(TValue));
         OnListChanging(args);
         if (args.Cancel)
         {
             return;
         }
     }
     if (RaiseListChangedEvents)
     {
         OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.Reset, -1, default(TValue)));
         OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
     }
 }
Exemplo n.º 4
0
        private void SetItem(TKey key, TValue value, int index)
        {
            var old = m_dict[key];

            if (RaiseListChangedEvents)
            {
                var args = new ListChgEventArgs <TValue>(this, ListChg.ItemPreRemove, index, old);
                OnListChanging(args);
                if (args.Cancel)
                {
                    return;
                }
            }
            if (RaiseListChangedEvents)
            {
                var args = new ListChgEventArgs <TValue>(this, ListChg.ItemPreAdd, index, value);
                OnListChanging(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            // Replace the item
            SetItemCore(key, value);

            if (RaiseListChangedEvents)
            {
                OnItemChanged(new ItemChgEventArgs <TValue>(index, old, value));
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, value, old));
            }
            if (RaiseListChangedEvents)
            {
                OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.ItemRemoved, index, old));
            }
            if (RaiseListChangedEvents)
            {
                OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.ItemAdded, index, value));
            }
        }
Exemplo n.º 5
0
        private void ClearItems()
        {
            if (RaiseListChangedEvents)
            {
                var args = new ListChgEventArgs <TValue>(this, ListChg.PreReset, -1, default(TValue));
                OnListChanging(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            ClearItemsCore();

            if (RaiseListChangedEvents)
            {
                OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.Reset, -1, default(TValue)));
                OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
Exemplo n.º 6
0
        private void RemoveItem(TKey key, int index)
        {
            var item = m_dict[key];

            if (RaiseListChangedEvents)
            {
                var args = new ListChgEventArgs <TValue>(this, ListChg.ItemPreRemove, index, item);
                OnListChanging(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            RemoveItemCore(key, index);

            if (RaiseListChangedEvents)
            {
                OnListChanging(new ListChgEventArgs <TValue>(this, ListChg.ItemRemoved, -1, item));
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
            }
        }
Exemplo n.º 7
0
 protected virtual void OnListChanging(ListChgEventArgs <TValue> args)
 {
     ListChanging?.Invoke(this, args);
 }