Пример #1
0
        public static void UnSubscribe(this INotifyCollectionChanged n, Action <NotifierPropertyChangedEventArgs> action,
                                       IList <string> targets)
        {
            if (CollectionHandlers.TryRemove(Tuple.Create(action, targets), out NotifyCollectionChangedEventHandler h))
            {
                if (targets.Count > 1)
                {
                    if (n is IList oldItems)
                    {
                        foreach (var item in oldItems)
                        {
                            if (targets.Count > 1)
                            {
                                var newTargets = targets.Skip(1).ToArray();

                                if (item is INotifyCollectionChanged oldCollection)
                                {
                                    oldCollection.UnSubscribe(action, newTargets);
                                }

                                if (item is INotifyPropertyChanged oldValue)
                                {
                                    oldValue.UnSubscribe(action, newTargets);
                                }
                            }

                            action(new NotifierPropertyChangedEventArgs("Item", item, null));
                        }
                    }
                }
                n.CollectionChanged -= h;
            }
        }
Пример #2
0
 /// <summary>
 /// Registers a collection handler which provides support for a certain type
 /// or multiple types of collections.
 /// </summary>
 /// <param name="handler">the collection handler</param>
 public void RegisterCollectionHandler(CollectionHandler handler)
 {
     CollectionHandlers.Insert(0, handler);
 }