Esempio n. 1
0
 private void Source2CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Move)
     {
         return;
     }
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         var filtered = new List <TSource>(SL.Intersect(sourceItems.Keys, source));
         sourceItems.Clear();
         OnAddItems(filtered);
     }
     if (e.OldItems != null)
     {
         var removed = new HashSet <TSource>(sourceItems.Comparer);
         foreach (TSource item in e.OldItems)
         {
             if (RemoveItem(item))
             {
                 removed.Add(item);
             }
         }
         var changed = SL.Where(source, item => removed.Contains(item));
         OnAddItems(changed);
     }
     if (e.NewItems != null)
     {
         var added = new HashSet <TSource>(sourceItems.Comparer);
         foreach (TSource item in e.NewItems)
         {
             if (AddItem(item))
             {
                 added.Add(item);
             }
         }
         var changed = SL.Where(source, item => added.Contains(item));
         OnRemoveItems(changed);
     }
 }