Exemplo n.º 1
0
 public Capture(ListBox listBox)
 {
     this.listBox = listBox;
     incc = listBox.ItemsSource as INotifyCollectionChanged;
     incc.CollectionChanged +=
         new NotifyCollectionChangedEventHandler(incc_CollectionChanged);
 }
        protected override SnapshotState CheckValueChanged(object newValue)
        {
            if (_listenedCollectionAsINotifyCollectionChanged != null &&
                ReferenceEquals(_listenedCollectionAsINotifyCollectionChanged, newValue))
            {
                return this.State;
            }

            ReleaseListeners();

            var newValueAsINotifyCollectionChanged = newValue as INotifyCollectionChanged;
            var newValueAsIEnumerable = newValue as IEnumerable;

            if (newValueAsINotifyCollectionChanged == null || newValueAsIEnumerable == null ||
                newValue.GetType() != this.SnapshotValue.GetType())
            {
                return SnapshotState.CHANGED;
            }

            _listenedCollectionAsINotifyCollectionChanged = newValueAsINotifyCollectionChanged;
            _listenedCollectionAsIEnumerable = newValueAsIEnumerable;
            _listenedCollectionAsINotifyCollectionChanged.CollectionChanged += OnCollectionChanged;

            return CheckCollectionChanged();
        }
 public CollectionObserver(INotifyCollectionChanged collection, Action<NotifyCollectionChangedEventArgs> collectionChanged)
 {
     _collectionChanged = collectionChanged;
     _collectionObserver = Observable.FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
         ev => collection.CollectionChanged += ev, ev => collection.CollectionChanged -= ev)
         .Subscribe(e => CollectionChanged(e.EventArgs));
 }
        /// <summary>
        /// Remove a handler for the given source's event.
        /// </summary>
        public static void RemoveHandler(INotifyCollectionChanged source, EventHandler<NotifyCollectionChangedEventArgs> handler)
        {
            if (handler == null)
                throw new ArgumentNullException("handler");

            CurrentManager.ProtectedRemoveHandler(source, handler);
        }
        public CollectionNotificationChainManager(INotifyCollectionChanged notifyingCollection)
            : this()
        {
            notifyingCollection.ThrowIfNull ("notifyingCollection");

            ObserveCollection (notifyingCollection);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CollectionObserver"/> class.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="mementoService">The memento service.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="collection"/> is <c>null</c>.</exception>
        public CollectionObserver(INotifyCollectionChanged collection, object tag = null, IMementoService mementoService = null)
            : base(tag, mementoService)
        {
            Argument.IsNotNull("collection", collection);

            _weakEventListener = this.SubscribeToWeakCollectionChangedEvent(collection, OnCollectionChanged);
        }
        /// <summary>
        /// Constructor with collection and property name</summary>
        /// <param name="collection">Collection whose changes are listened to</param>
        /// <param name="propertyName">Property whose value change is listened to</param>
        public CollectionChangeListener(INotifyCollectionChanged collection, string propertyName)
        {
            m_value = collection;
            PropertyName = propertyName;

            Subscribe();
        }
        /// <summary>
        /// Begins observing the given notifying collection.
        /// </summary>
        /// <param name="notifyingCollection"></param>
        public void ObserveCollection(INotifyCollectionChanged notifyingCollection)
        {
            notifyingCollection.ThrowIfNull ("notifyingCollection");

            if (IsDisposed) return;

            if (myObservedCollections.ContainsKey (notifyingCollection)) return;

            myObservedCollections[notifyingCollection] = () => notifyingCollection.CollectionChanged -= myCollectionChangedEventHandler;

            NotificationChainPropertyAttribute.CallProperties (notifyingCollection);

            notifyingCollection.CollectionChanged += myCollectionChangedEventHandler;

            var enumerable = notifyingCollection as IEnumerable;
            if (enumerable != null)
            {
                foreach (var item in enumerable)
                {
                    var inpc = item as INotifyPropertyChanged;
                    if (inpc != null)
                        base.Observe (inpc);
                }
            }
        }
Exemplo n.º 9
0
 private void DetachNotificationEvents(INotifyCollectionChanged notifyCollection)
 {
     if (notifyCollection != null)
     {
         notifyCollection.CollectionChanged -= OnCollectionChanged;
     }
 }
 public StationConnectionChecker(IStationFeedService stationFeedService,
     IConfigurationService configurationService)
 {
     ConfigurationService = configurationService;
     stationCollection = stationFeedService.CachedStations;
     stationCollection.CollectionChanged += StationCollection_OnCollectionChanged;
 }
Exemplo n.º 11
0
 public CollectionChangedEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
 {
     if (source == null) { throw new ArgumentNullException("source"); }
     if (handler == null) { throw new ArgumentNullException("handler"); }
     this.source = source;
     this.handler = handler;
 }
Exemplo n.º 12
0
        private UICollectionSynchronizer(IList<CardViewModel> collection, INotifyCollectionChanged collectionChanged, StackLayout stackLayout, GamePageModel gamePageModel)
        {
            this.stackLayout = stackLayout;
            this.gamePageModel = gamePageModel;
            ((INotifyCollectionChanged)collection).CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) => {
                if (e.Action == NotifyCollectionChangedAction.Reset) {
                    this.stackLayout.Children.Clear ();
                    this.mapper.Clear ();
                } else {
                    if(e.OldItems != null)
                    {
                        foreach (CardViewModel card in e.OldItems) {
                            this.RemoveItem(card);
                        }
                    }

                    if(e.NewItems != null)
                    {
                        foreach (CardViewModel card in e.NewItems) {
                            this.AddItem(card);
                        }
                    }
                }
            };
            foreach (CardViewModel card in collection) {
                this.AddItem (card);
            }
        }
		public CollectionSynchronizer(INotifyCollectionChanged source, ObservableCollection<object> target, IValueConverter valueConverter)
		{
			_source = source;
			_target = target;
			_valueConverter = valueConverter;
			_source.CollectionChanged += OnSourceCollectionChanged;
		}
 public void Include(INotifyCollectionChanged changed)
 {
     changed.CollectionChanged += (s, e) =>
     {
         var test = string.Format("{0}{1}{2}{3}{4}", e.Action, e.NewItems, e.NewStartingIndex, e.OldItems, e.OldStartingIndex);
     };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="WeakCollectionChangedListener"/>
 /// </summary>
 /// <param name="source">The source event source</param>
 /// <param name="listener">The listener event listener</param>
 private WeakCollectionChangedListener(
     INotifyCollectionChanged source,
     ICollectionChangedListener listener)
 {
     this._source = source;
     this._source.CollectionChanged += this.SourceCollectionChanged;
     this._weakListener = new WeakReference(listener);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CollectionObserver"/> class.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="mementoService">The memento service.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="collection"/> is <c>null</c>.</exception>
        public CollectionObserver(INotifyCollectionChanged collection, object tag = null, IMementoService mementoService = null)
            : base(tag, mementoService)
        {
            Argument.IsNotNull("collection", collection);

            _collection = collection;
            _collection.CollectionChanged += OnCollectionChanged;
        }
        public static void UnhookCollectionChangedEvent(INotifyCollectionChanged collection, object target, PropertyInfo property)
        {
            _collectionPropertyMap
                .Where(t => t.CollectionReference.Target == collection && t.TargetReference.Target == target && t.Property == property)
                .ToList().ForEach(t => _collectionPropertyMap.Remove(t));

            collection.CollectionChanged -= HandleCollectionChanged;
        }
        //
        //  Public Methods 
        //

        /// <summary>
        /// Add a listener to the given source's event. 
        /// </summary>
        public static void AddListener(INotifyCollectionChanged source, IWeakEventListener listener) 
        { 
            if (source == null)
                throw new ArgumentNullException("source"); 
            if (listener == null)
                throw new ArgumentNullException("listener");

            CurrentManager.ProtectedAddListener(source, listener); 
        }
Exemplo n.º 19
0
        private static NotifyCollectionChangedEventHandler SetupCollectionChangedEventHandler(DependencyObject dependencyObject,
                                                                                          INotifyCollectionChanged observableCollection)
        {
            NotifyCollectionChangedEventHandler sourceChangedHandler =
                (s, ev) => SelectedItemsCollectionChanged(dependencyObject, ev);
            observableCollection.CollectionChanged += sourceChangedHandler;

            return sourceChangedHandler;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Hookups the handler to the collection changed event. When the value changes it removes the handler.
        /// </summary>
        /// <param name="oldValue">The old collection.</param>
        /// <param name="newValue">The new collection.</param>
        /// <param name="handler">The handler to hookup.</param>
        public static void HookupToCollectionChanged(INotifyCollectionChanged oldValue, INotifyCollectionChanged newValue,
            NotifyCollectionChangedEventHandler handler)
        {
            if (oldValue != null)
                oldValue.CollectionChanged -= handler;

            if (newValue != null)
                newValue.CollectionChanged += handler;
        }
Exemplo n.º 21
0
 public Capture(ListView ListView)
 {
     this.ListView = ListView;
     this.incc = ListView.ItemsSource as INotifyCollectionChanged;
     if (this.incc != null)
     {
         this.incc.CollectionChanged += this.incc_CollectionChanged;
     }
 }
 /// <summary>
 /// Disconnects this listener from the collection change event
 /// </summary>
 internal void Disconnect()
 {
     if (this._source != null)
     {
         this._source.CollectionChanged -= this.SourceCollectionChanged;
         this._source = null;
         this._weakListener = null;
     }
 }
 void LegendItemsCollectionChangedHandler(INotifyCollectionChanged notifyCollectionChanged, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
 {
     switch (notifyCollectionChangedEventArgs.Action)
     {
         case NotifyCollectionChangedAction.Add:
             foreach (LegendItemViewModel newLegendItem in notifyCollectionChangedEventArgs.NewItems) 
                 if (LegendItems.All(l => l.SeriesName != newLegendItem.SeriesName)) LegendItems.Add(newLegendItem);
             break;
     }
 }
 internal void Disconnect()
 {
     if (this.source == null)
     {
         return;
     }
     this.source.CollectionChanged -= new NotifyCollectionChangedEventHandler(this.SourceCollectionChanged);
     this.source = null;
     this.weakListener = null;
 }
Exemplo n.º 25
0
        public static NotifyCollectionChangedEventHandler SetItemsCollection(this MapLayer layer, INotifyCollectionChanged collection, DataTemplate template)
        {
            if (collection == null) return null;

            Action<IList> RemoveMapOverlays = (items) =>
            {
                if (items == null || items.Count == 0) return;
                for (int i = layer.Count - 1; i >= 0; i--)
                    if (items.Contains(layer[i].Content))
                        layer.RemoveAt(i);
            };

            Action<IList> CreateMapOverlays = (items) =>
            {
                if (items == null || items.Count == 0) return;
                foreach (var item in items)
                {
                    var overlay = new MapOverlay();
                    var coord = item as IHasCoordinate;
                    overlay.ContentTemplate = template;
                    overlay.Content = item;
                    overlay.GeoCoordinate = coord.Coordinate;
                    overlay.PositionOrigin = new System.Windows.Point(0.5, 1);
                    layer.Add(overlay);
                }
            };

            NotifyCollectionChangedEventHandler ItemsChanged = (sender, e) =>
            {
                switch (e.Action)
                {
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                        CreateMapOverlays(e.NewItems);
                        break;
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                        break;
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                        RemoveMapOverlays(e.OldItems);
                        break;
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                        RemoveMapOverlays(e.OldItems);
                        CreateMapOverlays(e.NewItems);
                        break;
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                        layer.Clear();
                        CreateMapOverlays(collection as IList);
                        break;
                    default:
                        break;
                }
            };

            collection.CollectionChanged += ItemsChanged;
            return ItemsChanged;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Adds a weak event listener for a CollectionChanged event.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="handler">The event handler.</param>
        /// <exception cref="ArgumentNullException">source must not be <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">handler must not be <c>null</c>.</exception>
        protected void AddWeakEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
        {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (handler == null) { throw new ArgumentNullException("handler"); }

            CollectionChangedEventListener listener = new CollectionChangedEventListener(source, handler);

            collectionChangedListeners.Add(listener);

            CollectionChangedEventManager.AddListener(source, listener);
        }
        /// <summary> 
        /// Remove a listener to the given source's event.
        /// </summary> 
        public static void RemoveListener(INotifyCollectionChanged source, IWeakEventListener listener)
        {
            /* for app-compat, allow RemoveListener(null, x) - it's a no-op (see Dev10 796788)
            if (source == null) 
                throw new ArgumentNullException("source");
            */ 
            if (listener == null) 
                throw new ArgumentNullException("listener");
 
            CurrentManager.ProtectedRemoveListener(source, listener);
        }
Exemplo n.º 28
0
        private static void OnSelectedItemsChanged(INotifyCollectionChanged collection, IList oldItems, IList newItems)
        {
            isSyncingSelection = true;

            var gridViews = GetOrCreateGridViews(collection);
            foreach (var gridView in gridViews)
            {
                SyncSelection(gridView, oldItems, newItems);
            }

            isSyncingSelection = false;
        }
Exemplo n.º 29
0
        private static void OnSelectedItemsChanged(INotifyCollectionChanged collection, IList oldItems, IList newItems)
        {
            isSyncingSelection = true;

            var behaviors = GetOrCreateSelectionBehaviors(collection);
            foreach (var behavior in behaviors)
            {
                SyncSelection(behavior, oldItems, newItems);
            }

            isSyncingSelection = false;
        }
Exemplo n.º 30
0
 private static void SetupOnUnloadedHandler(DependencyObject dependencyObject, INotifyCollectionChanged observableCollection,
                                            NotifyCollectionChangedEventHandler sourceChangedHandler)
 {
     RoutedEventHandler unloadedEventHandler = null;
     unloadedEventHandler = (sender, args) =>
                                {
                                    observableCollection.CollectionChanged -= sourceChangedHandler;
                                    ((ListViewBase)sender).SelectionChanged -= OnGridSelectionChanged;
                                    ((ListViewBase)sender).Unloaded -= unloadedEventHandler;
                                };
     ((ListViewBase)dependencyObject).Unloaded += unloadedEventHandler;
 }
Exemplo n.º 31
0
 /// <summary>
 ///  Removes a previously added listener from the provided source.
 /// </summary>
 /// <param name = "source">The source.</param>
 /// <param name = "listener">The listener.</param>
 public static void RemoveListener(INotifyCollectionChanged source, IWeakEventListener listener)
 {
     CurrentManager.ProtectedRemoveListener(source, listener);
 }
Exemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReactiveTableViewSource{TSource}"/> class.
 /// </summary>
 /// <param name="tableView">The table view.</param>
 /// <param name="collection">The collection.</param>
 /// <param name="cellKey">The cell key.</param>
 /// <param name="sizeHint">The size hint.</param>
 /// <param name="initializeCellAction">The initialize cell action.</param>
 public ReactiveTableViewSource(UITableView tableView, INotifyCollectionChanged collection, NSString cellKey, float sizeHint, Action <UITableViewCell> initializeCellAction = null)
     : this(tableView)
 {
     Data = new[] { new TableSectionInformation <TSource, UITableViewCell>(collection, cellKey, sizeHint, initializeCellAction) };
 }
Exemplo n.º 33
0
        /// <summary>
        /// Binds the property on many elements into a combination for which <paramref name="handler"/> is invoked whenever its value changes.
        /// This is useful for instance when you have a property on a collection that is the reduction of a property of collection element (in which case you can use the handler to set the reduced value).
        /// </summary>
        /// <typeparam name="TElement"> The type of the elements of the specified observable collection. </typeparam>
        /// <typeparam name="TElementProperty"> The type of the property on <typeparamref name="TElement"/> whose name is <paramref name="propertyName"/> and whose values are to be reduced. </typeparam>
        /// <param name="collection"> The collection to monitor for property changes. </param>
        /// <param name="propertyName"> The name of the property on the collection elements to monitor. </param>
        /// <param name="handler"> The function handling the change of the reduced value. The first argument is the collection and the second the new value. </param>
        /// <param name="combine"> The function taking the previous reduced value and an updated value of one of the properies, and returns their reduction. </param>
        /// <param name="valueIfCollectionEmpty"> The value to be taken if the specified collection is empty. </param>
        /// <param name="equalityComparer"> The function comparing <typeparamref name="TElementProperty"/>s for equality, determining when to invoke <paramref name="handler"/>. </param>
        public static void BindCollective <TElement, TElementProperty>(this INotifyCollectionChanged collection,
                                                                       string propertyName,
                                                                       PropertyChangedEventHandler handler,
                                                                       Func <TElementProperty /*previous resultant*/, TElementProperty /*new property*/, TElementProperty> combine,
                                                                       Option <TElementProperty> valueIfCollectionEmpty      = default,
                                                                       IEqualityComparer <TElementProperty> equalityComparer = null)
        {
            Contract.Requires(collection != null);
            Contract.Requires(collection is IEnumerable <TElement>);
            Contract.Requires(HasProperty <TElement>(propertyName));
            Contract.Requires(handler != null);
            Contract.Requires(combine != null);

            equalityComparer = equalityComparer ?? EqualityComparer <TElementProperty> .Default;

            Option <TElementProperty> resultant = Option <TElementProperty> .None;

            collection.Bind(propertyName, elementPropertyChanged, typeof(TElement), true, onElementRemoved);
            setResultant(recomputeResultant());             // if handler shouldn't be triggered on the initially present elements, set as resultant = recomputeResultant() rather than through setResultant


            Option <TElementProperty> recomputeResultant()
            {
                Option <TElementProperty> result = Option <TElementProperty> .None;

                foreach (var element in (IEnumerable <TElement>)collection)
                {
                    var propValue = GetPropertyValue <TElement, TElementProperty>(element, propertyName);

                    if (!result.HasValue)
                    {
                        result = propValue;
                    }
                    else
                    {
                        result = combine(result.Value, propValue);
                    }
                }
                return(result);                // returns Option.None when the collection is empty
            }

            void onElementRemoved(object sender, PropertyChangedEventArgs e)
            {
                Contract.Assert(resultant.HasValue);

                var propValue = GetPropertyValue <TElement, TElementProperty>((TElement)sender, e.PropertyName);

                if (equalityComparer.Equals(propValue, resultant.Value))                 // if the resultant value was removed from the collection
                {
                    setResultant(recomputeResultant());
                }
            }

            void elementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == propertyName)
                {
                    var newValue     = GetPropertyValue <TElement, TElementProperty>((TElement)sender, e.PropertyName);
                    var newResultant = resultant.HasValue ? combine(resultant.Value, newValue) : newValue;
                    setResultant(newResultant);
                }
            }

            void setResultant(Option <TElementProperty> newResultant)
            {
                // newResultant: None means the collection is empty.
                TElementProperty newValue;

                if (newResultant.HasValue)
                {
                    newValue = newResultant.Value;
                }
                else
                {
                    if (valueIfCollectionEmpty.HasValue)
                    {
                        newValue = valueIfCollectionEmpty.Value;
                    }
                    else
                    {
                        // don't trigger the handler if there is no value to set
                        return;
                    }
                }

                if (resultant.HasValue)
                {
                    TElementProperty oldValue = resultant.Value;
                    if (!equalityComparer.Equals(oldValue, newValue))
                    {
                        handle(oldValue, newValue);
                    }
                }
                else
                {
                    TElementProperty oldValue = valueIfCollectionEmpty.ValueOrDefault();
                    handle(oldValue, newValue);
                }
            }

            void handle(TElementProperty oldValue, TElementProperty newValue)
            {
                var arg = new PropertyMutatedEventArgs <TElementProperty>(propertyName, oldValue, newValue);

                handler(collection, arg);
            }
        }
Exemplo n.º 34
0
        public static CollectionProcessing <TSourceItem, TReturnValue> CollectionItemsProcessing <TSourceItem, TReturnValue>(this
                                                                                                                             INotifyCollectionChanged source,
                                                                                                                             Func <TSourceItem[], ICollectionComputing, TReturnValue[]> newItemsProcessor   = null,
                                                                                                                             Action <TSourceItem[], ICollectionComputing, TReturnValue[]> oldItemsProcessor = null,
                                                                                                                             Action <TSourceItem, ICollectionComputing, TReturnValue> moveItemProcessor     = null)

        {
            return(new CollectionProcessing <TSourceItem, TReturnValue>(
                       source: source,
                       newItemsProcessor: newItemsProcessor,
                       oldItemsProcessor: oldItemsProcessor,
                       moveItemProcessor: moveItemProcessor));
        }
Exemplo n.º 35
0
 private static INotifyCollectionChanged getSource(
     INotifyCollectionChanged source,
     Expression <Func <TSourceItem, INotifyCollectionChanged> > selectorExpression)
 {
     return(source.Selecting(selectorExpression));
 }
Exemplo n.º 36
0
 public static MvxNotifyCollectionChangedEventSubscription WeakSubscribe(this INotifyCollectionChanged source,
                                                                         EventHandler <NotifyCollectionChangedEventArgs> eventHandler)
 {
     return(new MvxNotifyCollectionChangedEventSubscription(source, eventHandler));
 }
Exemplo n.º 37
0
 /// <summary>
 /// Registers a collection to the previous and next states of this operation.
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="collection">The collection to register.</param>
 public void RegisterCollection([NotNull] SelectionScope scope, [NotNull] INotifyCollectionChanged collection)
 {
     previousState.RegisterCollection(scope, collection);
     nextState.RegisterCollection(scope, collection);
 }
 public void Include(INotifyCollectionChanged changed)
 {
     changed.CollectionChanged += (s, e) => { var test = $"{e.Action}{e.NewItems}{e.NewStartingIndex}{e.OldItems}{e.OldStartingIndex}"; };
 }
 public CollectionChangedTrigger(INotifyCollectionChanged source, IScheduler tripScheduler, Logger logger)
     : this(source, -1, tripScheduler, logger)
 {
 }
 public void Include(INotifyCollectionChanged changed)
 {
     changed.CollectionChanged += (s, e) => { var test = string.Format("{0}{1}{2}{3}{4}", e.Action, e.NewItems, e.NewStartingIndex, e.OldItems, e.OldStartingIndex); };
 }
Exemplo n.º 41
0
        private static void SelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            INotifyCollectionChanged collection = (INotifyCollectionChanged)sender;

            OnSelectedItemsChanged(collection, args.OldItems, args.NewItems);
        }
Exemplo n.º 42
0
 public static void SetSelectedItems(DependencyObject obj, INotifyCollectionChanged value)
 {
     obj.SetValue(SelectedItemsProperty, value);
 }
Exemplo n.º 43
0
 /* ----------------------------------------------------------------- */
 ///
 /// ToBindingSource
 ///
 /// <summary>
 /// INotifyCollectionChanged を実装するコレクションを
 /// BindingSource オブジェクトに変換します。
 /// </summary>
 ///
 /// <remarks>
 /// CollectionChanged イベント発生時に ResetBindings(false) を
 /// 実行します。
 /// </remarks>
 ///
 /// <param name="src">コレクションオブジェクト</param>
 ///
 /* ----------------------------------------------------------------- */
 public static BindingSource ToBindingSource(this INotifyCollectionChanged src)
 => ToBindingSource(src, SynchronizationContext.Current);
Exemplo n.º 44
0
 public static ObservableVector <T> ToObservableVector <T>(this INotifyCollectionChanged s)
 {
     return(new ObservableVector <T>(s));
 }
 public LastComputing(
     INotifyCollectionChanged source,
     TSourceItem defaultValue = default(TSourceItem)) : base(source, getIndex(source), defaultValue)
 {
 }
Exemplo n.º 46
0
 public ObservableCollectionWrapper(ICollection collection, INotifyCollectionChanged notifier)
 {
     _collection = collection;
     notifier.CollectionChanged += (sender, args) => OnCollectionChanged(args);
 }
Exemplo n.º 47
0
 public Extending(
     INotifyCollectionChanged source) : base(Utils.getCapacity(source))
 {
     _source = source;
     _thisAsSourceCollectionChangeProcessor = this;
 }
        private void ConnectToCollectionChangedOnScheduler(INotifyCollectionChanged firstCollection, INotifyCollectionChanged secondCollection, IScheduler notificationScheduler)
        {
            firstCollection.CollectionChanged += (_, args) =>
                                                 notificationScheduler.Schedule(Unit.Default, (__, ___) =>
                                                                                OnFirstCollectionChanged(args));

            secondCollection.CollectionChanged += (_, args) =>
                                                  notificationScheduler.Schedule(Unit.Default, (__, ___) =>
                                                                                 OnSecondCollectionChanged(args));
        }
Exemplo n.º 49
0
 /// <summary>
 /// Initializes a new instance of <see cref="CollectionActiveAwareBehavior"/>.
 /// </summary>
 /// <param name="collection">The collection to monitor.</param>
 /// <remarks>This instance will keep a <see cref="WeakReference"/> to the
 /// <paramref name="collection"/>, so the collection can be garbage collected.</remarks>
 public CollectionActiveAwareBehavior(INotifyCollectionChanged collection)
 {
     _collection = new WeakReference(collection);
 }
Exemplo n.º 50
0
        public static CollectionDisposing <TSourceItem> CollectionDisposing <TSourceItem>(this
                                                                                          INotifyCollectionChanged source) where TSourceItem : IDisposable

        {
            return(new CollectionDisposing <TSourceItem>(
                       source: source));
        }
Exemplo n.º 51
0
 /// <summary>
 /// Registers a weak handler to <see cref="INotifyCollectionChanged.CollectionChanged"/>.
 /// </summary>
 /// <typeparam name="TSubscriber">The type of the event subscriber.</typeparam>
 /// <param name="source">The event source.</param>
 /// <param name="subscriber">The event subscriber.</param>
 /// <param name="weakHandler">The weak handler.</param>
 /// <returns>A registration object that can be used to deregister from the event.</returns>
 public static IDisposable RegisterCollectionChangedWeak <TSubscriber>(this INotifyCollectionChanged source,
                                                                       TSubscriber subscriber, [EmptyCapture] Action <TSubscriber, object, NotifyCollectionChangedEventArgs> weakHandler)
     where TSubscriber : class
 {
     return(new WeakNotifyCollectionChangedHandler <TSubscriber>(source, subscriber, weakHandler));
 }
        private void ConnectToCollectionChanged(INotifyCollectionChanged firstCollection, INotifyCollectionChanged secondCollection)
        {
            firstCollection.CollectionChanged += (_, args) => OnFirstCollectionChanged(args);

            secondCollection.CollectionChanged += (_, args) => OnSecondCollectionChanged(args);
        }
Exemplo n.º 53
0
        /// <summary>
        /// Rebuilds the list if a collection changes.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Information about the event.</param>
        private void ChildCollectionsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Debug.Assert(e.Action != NotifyCollectionChangedAction.Reset, "Reset is not supported.");

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                e.NewItems
                .OfType <IList>()
                .ForEachWithIndex((newCollection, index) =>
                {
                    int startingIndex = GetStartingIndexOfCollectionAtIndex(e.NewStartingIndex + index);
                    foreach (T item in newCollection.OfType <T>().Reverse())
                    {
                        this.Mutate(items => items.Insert(startingIndex, item));
                    }

                    INotifyCollectionChanged notifyCollectionChanged = newCollection as INotifyCollectionChanged;
                    if (notifyCollectionChanged != null)
                    {
                        notifyCollectionChanged.CollectionChanged += ChildCollectionCollectionChanged;
                    }
                });
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (IList oldCollection in e.OldItems)
                {
                    INotifyCollectionChanged notifyCollectionChanged = oldCollection as INotifyCollectionChanged;
                    if (notifyCollectionChanged != null)
                    {
                        notifyCollectionChanged.CollectionChanged -= ChildCollectionCollectionChanged;
                    }

                    foreach (T item in oldCollection)
                    {
                        this.Mutate(items => items.Remove(item));
                    }
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Replace)
            {
                foreach (IList oldCollection in e.OldItems)
                {
                    INotifyCollectionChanged notifyCollectionChanged = oldCollection as INotifyCollectionChanged;
                    if (notifyCollectionChanged != null)
                    {
                        notifyCollectionChanged.CollectionChanged -= ChildCollectionCollectionChanged;
                    }
                }

                foreach (IList newCollection in e.NewItems)
                {
                    INotifyCollectionChanged notifyCollectionChanged = newCollection as INotifyCollectionChanged;
                    if (notifyCollectionChanged != null)
                    {
                        notifyCollectionChanged.CollectionChanged += ChildCollectionCollectionChanged;
                    }
                }

                Rebuild();
            }
        }
Exemplo n.º 54
0
 /// <summary>
 /// Unregisters a collection from the previous and next states of this operation.
 /// </summary>
 /// <param name="collection">The collection to unregister.</param>
 public void UnregisterCollection([NotNull] INotifyCollectionChanged collection)
 {
     previousState.UnregisterCollection(collection);
     nextState.UnregisterCollection(collection);
 }
Exemplo n.º 55
0
        public static CollectionProcessingVoid <TSourceItem> CollectionItemProcessing <TSourceItem>(this
                                                                                                    INotifyCollectionChanged source,
                                                                                                    Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > newItemProcessor  = null,
                                                                                                    Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > oldItemProcessor  = null,
                                                                                                    Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > moveItemProcessor = null)

        {
            return(new CollectionProcessingVoid <TSourceItem>(
                       source: source,
                       newItemProcessor: newItemProcessor,
                       oldItemProcessor: oldItemProcessor,
                       moveItemProcessor: moveItemProcessor));
        }
Exemplo n.º 56
0
        /// <summary>
        /// Invokes the specified handler for each change of the specified property on any of the elements in the specified collection.
        /// Note that the handler is not invoked for elements already present, nor if items are added where the property already has a value.
        /// </summary>
        /// <param name="collection"> The collection of elements on which to monitor property changes. </param>
        /// <param name="handler"> The action invoked when the property changes. </param>
        /// <param name="propertyName"> The name of the property to monitor. </param>
        /// <param name="handleNewItems"> Indicates whether the relevant property on an item added to the collection should be treated as though it changed. </param>
        public static void Bind(this INotifyCollectionChanged collection,
                                string propertyName,
                                PropertyChangedEventHandler handler,
                                Type elementType    = null,
                                bool handleNewItems = false,
                                PropertyChangedEventHandler onRemove = null)
        {
            Contract.Requires(collection != null);
            Contract.Requires(collection is System.Collections.IEnumerable);
            Contract.Requires(elementType == null || HasProperty(propertyName, elementType));


            collection.CollectionChanged += collectionChanged;
            var collectionList = collection as System.Collections.IList ?? ((System.Collections.IEnumerable)collection).Cast <object>().ToList();

            if (collectionList.Count != 0)
            {
                elementType = elementType ?? collectionList[0].GetType();
                Contract.Requires(HasProperty(propertyName, elementType));

                collectionChanged(collection, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, collectionList));
            }


            void collectionChanged(object sender, NotifyCollectionChangedEventArgs e)
            {
                if (e.Action == NotifyCollectionChangedAction.Move)
                {
                    return;
                }

                if (e.NewItems != null)
                {
                    foreach (var newItem in e.NewItems)
                    {
                        Contract.Requires(newItem is INotifyPropertyChanged, "This binding requires that all elements be non-null and implement INotifyPropertyChanged");
                        ((INotifyPropertyChanged)newItem).PropertyChanged += propertyChanged;
                        if (handleNewItems)
                        {
                            handler(newItem, PropertyMutatedEventArgsExtensions.From(newItem, propertyName, elementType));
                        }
                    }
                }
                if (e.OldItems != null)
                {
                    foreach (var newItem in e.OldItems)
                    {
                        ((INotifyPropertyChanged)newItem).PropertyChanged -= propertyChanged;
                        onRemove?.Invoke(newItem, PropertyMutatedEventArgsExtensions.From(newItem, propertyName, GetPropertyValue(newItem, propertyName, elementType), newValue: null, elementType));
                    }
                }
            }

            void propertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == propertyName)
                {
                    handler(sender, e);
                }
            }
        }
Exemplo n.º 57
0
 private static INotifyCollectionChanged getSource(INotifyCollectionChanged source)
 {
     return(source.Casting <object>().Filtering(item => item is TResultItem));
 }
Exemplo n.º 58
0
 public OfTypeComputing(
     INotifyCollectionChanged source) : base(getSource(source))
 {
     _sourceOfTypeComputing = source;
 }
Exemplo n.º 59
0
        private static void AddAssociation(INotifyCollectionChanged collection, ChartSelectionBehavior behavior)
        {
            List <ChartSelectionBehavior> behaviors = GetOrCreateSelectionBehaviors(collection);

            behaviors.Add(behavior);
        }
Exemplo n.º 60
0
        public static void Raise <T>(this NotifyCollectionChangedEventHandler handler, INotifyCollectionChanged source, NotifyCollectionChangedAction action, T item, int index)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var args = new NotifyCollectionChangedEventArgs(action, item, index);

            handler?.Invoke(source, args);
        }