Advertisement
Guest User

asc

a guest
Jul 3rd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. class NotifiableCollection<T> : Collection<T>, INotifyCollectionChanged
  2. {
  3.     public NotifiableCollection() { }
  4.  
  5.     protected override void InsertItem(int index, T item)
  6.     {
  7.         base.InsertItem(index, item);
  8.         OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
  9.     }
  10.  
  11.     protected override void RemoveItem(int index)
  12.     {
  13.         T item = base[index];
  14.         base.RemoveItem(index);
  15.         OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
  16.     }
  17.  
  18.     protected override void ClearItems()
  19.     {
  20.         base.ClearItems();
  21.         OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
  22.     }
  23.  
  24.     public void Move(int oldIndex, int newIndex)
  25.     {
  26.         T item = base[oldIndex];
  27.         base.SetItem(newIndex, item);
  28.         OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move,
  29.             item, newIndex, oldIndex));
  30.     }
  31.     protected override void SetItem(int index, T item)
  32.     {
  33.         T oldValue = base[index];
  34.         base.SetItem(index, item);
  35.  
  36.         OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace,
  37.                 item, oldValue));
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement