コード例 #1
0
 private void HandleCollectionChange(object sender, NotifyCollectionChangedEventArgs args)
 {
     if (_watcherList != null)
     {
         if (args.Action == NotifyCollectionChangedAction.Remove || args.Action == NotifyCollectionChangedAction.Replace || args.Action == NotifyCollectionChangedAction.Move)
         {
             if (args.OldItems.Count > 1)
             {
                 throw new NotSupportedException("Multi-value collection change notifications are not supported.");
             }
             foreach (var item in args.OldItems.OfType <T>())
             {
                 _watcherList.Remove(args.OldStartingIndex);
             }
         }
         if (args.Action == NotifyCollectionChangedAction.Add || args.Action == NotifyCollectionChangedAction.Replace || args.Action == NotifyCollectionChangedAction.Move)
         {
             if (args.NewItems.Count > 1)
             {
                 throw new NotSupportedException("Multi-value collection change notifications are not supported.");
             }
             foreach (var item in args.NewItems.OfType <T>())
             {
                 _watcherList.Add(args.NewStartingIndex, item);
             }
         }
         if (args.Action == NotifyCollectionChangedAction.Reset)
         {
             _watcherList.Reset(_collection);
         }
     }
     OnCollectionChanged(args);
 }