예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementActioner&lt;TElement&gt;"/> class.
        /// </summary>
        /// <param name="dispatcher">The dispatcher.</param>
        /// <param name="collection">The collection.</param>
        /// <param name="addAction">The add action.</param>
        /// <param name="removeAction">The remove action.</param>
        public ElementActioner(IBindableCollection <TElement> collection, Action <TElement> addAction, Action <TElement> removeAction, IDispatcher dispatcher)
            : base(dispatcher)
        {
            _addAction    = addAction;
            _removeAction = removeAction;
            _collection   = collection;

            _copy = new BindableCollection <TElement>(dispatcher);
            _collection_CollectionChangedHandler = Weak.Event <NotifyCollectionChangedEventArgs>(Collection_CollectionChanged);
            _collection.CollectionChanged       += _collection_CollectionChangedHandler.HandlerProxy.Handler;

            var internalBindableCollection = collection as IBindableCollection <TElement>;

            if (internalBindableCollection != null && !internalBindableCollection.HasEvaluated)
            {
                internalBindableCollection.Evaluating += (sender, e) =>
                {
                    foreach (var element in e.ItemsYieldedFromEvaluation)
                    {
                        HandleElement(NotifyCollectionChangedAction.Add, element);
                        _copy.Add(element);
                    }
                };
            }
            else
            {
                _collection.ForEach(element =>
                {
                    HandleElement(NotifyCollectionChangedAction.Add, element);
                    _copy.Add(element);
                });
            }
        }
예제 #2
0
 public ElementActioner(IBindableCollection <TElement> collection, Action <TElement> addAction, Action <TElement> removeAction, IDispatcher dispatcher)
     : base(dispatcher)
 {
     _addAction    = addAction;
     _removeAction = removeAction;
     _collection   = collection;
     _copy         = new BindableCollection <TElement>(dispatcher);
     _collection_CollectionChangedHandler = Weak.Event <NotifyCollectionChangedEventArgs>(Collection_CollectionChanged);
     _collection.CollectionChanged       += _collection_CollectionChangedHandler.HandlerProxy.Handler;
     if (!(collection?.HasEvaluated ?? true))
     {
         collection.Evaluating += delegate(object sender, EvaluatingEventArgs <TElement> e)
         {
             foreach (var item in e.ItemsYieldedFromEvaluation)
             {
                 HandleElement(NotifyCollectionChangedAction.Add, item);
                 _copy.Add(item);
             }
         };
     }
     else
     {
         _collection.ForEach(delegate(TElement element)
         {
             HandleElement(NotifyCollectionChangedAction.Add, element);
             _copy.Add(element);
         });
     }
 }
예제 #3
0
 private void HandleReset()
 {
     _copy.ForEach(a => HandleElement(NotifyCollectionChangedAction.Remove, a));
     _collection.ForEach(a => HandleElement(NotifyCollectionChangedAction.Add, a));
     _copy.Clear();
     _copy.AddRange(_collection);
 }