public static IObservable <ItemAdded <T> > ObserveAddedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemAdded <T> >();

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                case NotifyCollectionChangedAction.Replace:
                    subject.OnNext(new ItemAdded <T>((T)e.NewItems[0], e.NewStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = 0; i < list.Count; ++i)
                    {
                        subject.OnNext(new ItemAdded <T>(list[i], i));
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
 public ProfileOptionsActionsPage(ProfileOptions profile)
 {
     _profile = profile;
     Pages    = profile.Actions;
     SyncPagesWithActionCollection(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, profile.Actions));
     CollectionChangedEventManager.AddHandler(profile.Actions, SyncPagesWithActionCollection);
 }
Esempio n. 3
0
 public ItemCountSynchronizer(INavigationNode node, EmailFolder folder)
 {
     this.node   = node;
     this.folder = folder;
     CollectionChangedEventManager.AddHandler(folder.Emails, EmailsCollectionChanged);
     UpdateItemCount();
 }
Esempio n. 4
0
        /// <summary>
        /// コレクションの依存関係プロパティ変更イベントハンドラです。
        /// </summary>
        /// <param name="d">イベント発行元</param>
        /// <param name="e">イベント引数</param>
        private static void OnCollectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var colorMap = d as ColorMap;

            if (e.OldValue != null)
            {
                if (e.OldValue is INotifyCollectionChanged)
                {
#if NET4
                    (e.OldValue as INotifyCollectionChanged).CollectionChanged -= colorMap.OnCollectionChanged;
#else
                    CollectionChangedEventManager.RemoveHandler(e.OldValue as INotifyCollectionChanged, colorMap.OnCollectionChanged);
#endif
                }
            }
            if (e.NewValue != null)
            {
                if (e.NewValue is INotifyCollectionChanged)
                {
#if NET4
                    (e.OldValue as INotifyCollectionChanged).CollectionChanged += colorMap.OnCollectionChanged;
#else
                    CollectionChangedEventManager.AddHandler(e.NewValue as INotifyCollectionChanged, colorMap.OnCollectionChanged);
#endif
                }
            }

            colorMap.UpdateRendering_GraphBitmap();
        }
        /// <summary>Listens to CollectionChanged events and and invokes a callback.
        /// The benefit is a weak subscription that keeps a strong reference while the subscriber is alive.</summary>
        protected void ForwardCollectionEvents(INotifyCollectionChanged source, Action notifyHandler)
        {
            EventHandler <NotifyCollectionChangedEventArgs> func = (sender, e) => notifyHandler();

            funcReferences.Add(func);
            CollectionChangedEventManager.AddHandler(source, func);
        }
Esempio n. 6
0
        private void RegisterEventHandlers(IDockControl dataContext)
        {
            if (dataContext == null)
            {
                return;
            }

            // Attach to IDockControl.
            if (dataContext.DockStrategy == null)
            {
                throw new DockException("IDockControl.DockStrategy must not be null.");
            }

            DockStrategy = dataContext.DockStrategy;

            // Observe IDockControl properties.
            PropertyChangedEventManager.AddHandler(dataContext, OnDockStrategyChanged, nameof(IDockControl.DockStrategy));
            PropertyChangedEventManager.AddHandler(dataContext, OnActiveItemChanged, nameof(IDockControl.ActiveDockTabItem));
            //PropertyChangedEventManager.AddHandler(dataContext, OnActivePaneChanged, nameof(IDockControl.ActiveDockTabPane));

            // The ICollectionView is used to filter IFloatWindows.
            var collectionView            = CollectionViewSource.GetDefaultView(dataContext.FloatWindows);
            var collectionViewLiveShaping = collectionView as ICollectionViewLiveShaping;

            if (collectionViewLiveShaping != null && collectionViewLiveShaping.CanChangeLiveFiltering)
            {
                collectionViewLiveShaping.LiveFilteringProperties.Clear();
                collectionViewLiveShaping.LiveFilteringProperties.Add(nameof(IFloatWindow.IsVisible));
                collectionViewLiveShaping.IsLiveFiltering = true;
                collectionView.Filter = floatWindow => ((IFloatWindow)floatWindow).IsVisible;
            }
            CollectionChangedEventManager.AddHandler(collectionView, OnFloatWindowsChanged);
        }
            public TrackAffiliationData(SelectionProperties context, TrackViewModel track)
            {
                this.context = context;
                _track       = track;

                CollectionChangedEventManager.AddHandler(track.Blocks, (sender, e) => Notify(nameof(AffiliationState)));
            }
Esempio n. 8
0
 public PropertyChangedListener(ObservableCollection <T> collection, string propertyName = "")
 {
     _collection   = collection;
     _propertyName = propertyName ?? "";
     AddRange(collection);
     CollectionChangedEventManager.AddHandler(collection, CollectionChanged);
 }
Esempio n. 9
0
 public PropertyChangedListener(ObservableCollection <T> collection, string propertyName = "")
 {
     this.collection   = collection;
     this.propertyName = propertyName ?? string.Empty;
     this.AddRange(collection);
     CollectionChangedEventManager.AddHandler(collection, this.CollectionChanged);
 }
Esempio n. 10
0
        private static void OnSourceErrorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var node = Scope.GetNode(d) as InputNode;

            if (node == null)
            {
                // this happens when disposing
                return;
            }

            var oldErrors = (ReadOnlyObservableCollection <ValidationError>)e.OldValue;

            if (ShouldTrack(oldErrors))
            {
                CollectionChangedEventManager.RemoveHandler(oldErrors, node.OnSourceErrorsChanged);
            }

            var newErrors = (ReadOnlyObservableCollection <ValidationError>)e.NewValue;

            node.ErrorCollection.Remove(oldErrors);
            node.ErrorCollection.Add(newErrors);

            if (ShouldTrack(newErrors))
            {
                CollectionChangedEventManager.AddHandler(newErrors, node.OnSourceErrorsChanged);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SynchronizingCollection&lt;T, TOriginal&gt;"/> class.
        /// </summary>
        /// <param name="originalCollection">The original collection.</param>
        /// <param name="factory">The factory which is used to create new elements in this collection.</param>
        /// <exception cref="ArgumentNullException">The argument originalCollection must not be null.</exception>
        /// <exception cref="ArgumentNullException">The argument factory must not be null.</exception>
        public SynchronizingCollection(IEnumerable <TOriginal> originalCollection, Func <TOriginal, T> factory)
            : base(new ObservableCollection <T>())
        {
            if (originalCollection == null)
            {
                throw new ArgumentNullException("originalCollection");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            mapping = new List <Tuple <TOriginal, T> >();
            this.originalCollection = originalCollection;
            this.factory            = factory;
            itemComparer            = EqualityComparer <T> .Default;
            originalItemComparer    = EqualityComparer <TOriginal> .Default;

            INotifyCollectionChanged collectionChanged = originalCollection as INotifyCollectionChanged;

            if (collectionChanged != null)
            {
                CollectionChangedEventManager.AddHandler(collectionChanged, OriginalCollectionChanged);
            }

            innerCollection = (ObservableCollection <T>)Items;
            foreach (TOriginal item in originalCollection)
            {
                innerCollection.Add(CreateItem(item));
            }
        }
Esempio n. 12
0
        /// <summary> Initializes a new instance of the <see cref="SynchronizingCollection&lt;T, TOriginal&gt;"/> class. </summary>
        /// <param name="_originalCollection">The original collection.</param>
        /// <param name="_factory">The factory which is used to create new elements in this collection.</param>
        /// <exception cref="ArgumentNullException">The argument originalCollection must not be null.</exception>
        /// <exception cref="ArgumentNullException">The argument factory must not be null.</exception>
        public SynchronizingCollection(IEnumerable <TOriginal> _originalCollection, Func <TOriginal, T> _factory)
            : base(new ObservableCollection <T>())
        {
            if (null == _originalCollection)
            {
                throw new ArgumentNullException(nameof(_originalCollection));
            }
            if (null == _factory)
            {
                throw new ArgumentNullException(nameof(_factory));
            }

            m_Mapping              = new List <Tuple <TOriginal, T> >();
            m_OriginalCollection   = _originalCollection;
            m_Factory              = _factory;
            m_ItemComparer         = EqualityComparer <T> .Default;
            m_OriginalItemComparer = EqualityComparer <TOriginal> .Default;

            INotifyCollectionChanged collectionChanged = _originalCollection as INotifyCollectionChanged;

            if (null != collectionChanged)
            {
                CollectionChangedEventManager.AddHandler(collectionChanged, OriginalCollectionChanged);
            }

            m_InnerCollection = (ObservableCollection <T>) this.Items;
            foreach (TOriginal _item in _originalCollection)
            {
                m_InnerCollection.Add(CreateItem(_item));
            }
        }
Esempio n. 13
0
        private static void AutoScrollPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var scroller = obj as ScrollViewer;

            if (scroller == null || args.OldValue == args.NewValue)
            {
                return;
            }

            if (args.OldValue != null)
            {
                var coll = (INotifyCollectionChanged)args.OldValue;
                CollectionChangedEventManager.RemoveHandler(coll, AutoScrollSource_CollectionChanged);
                WeakEventManager <ScrollViewer, SizeChangedEventArgs> .RemoveHandler(scroller, "SizeChanged", ScrollViewer_SizeChanged);

                WeakPair pair = Get(coll, (p, _, __) => p);
                if (pair != null)
                {
                    _pairs.Remove(pair);
                }
            }

            if (args.NewValue != null)
            {
                var coll = (INotifyCollectionChanged)args.NewValue;
                CollectionChangedEventManager.AddHandler(coll, AutoScrollSource_CollectionChanged);
                WeakEventManager <ScrollViewer, SizeChangedEventArgs> .AddHandler(scroller, "SizeChanged", ScrollViewer_SizeChanged);

                AddPair(coll, scroller);
            }
        }
Esempio n. 14
0
 private ViewModelCollection(IList <TModel> models, Func <TModel, TViewModel> viewModelFactory)
 {
     CollectionChangedEventManager.AddHandler((INotifyCollectionChanged)models, SourceCollectionChanged);
     m_models           = models;
     m_viewModelFactory = viewModelFactory;
     m_viewModelMap     = new ConditionalWeakTable <TModel, TViewModel>();
     m_viewModels       = new List <TViewModel>(models.Select(m => GetOrCreateVM(m)));
 }
Esempio n. 15
0
 private void ListenToCollectionChanges()
 {
     Debug.Assert(m_vector != null);
     if (m_vector is INotifyCollectionChanged incc)
     {
         CollectionChangedEventManager.AddHandler(incc, OnCollectionChanged);
     }
 }
 private object InitializeTranscodingListView()
 {
     TranscodingListViewModel.TranscodingManager     = transcodingManager;
     TranscodingListViewModel.InsertFilesAction      = InsertFiles;
     TranscodingListViewModel.InsertMusicFilesAction = InsertMusicFiles;
     CollectionChangedEventManager.AddHandler((INotifyCollectionChanged)TranscodingListViewModel.SelectedTranscodeItems, SelectedTranscodeItemsCollectionChanged);
     return(TranscodingListViewModel.View);
 }
 // Token: 0x06001B48 RID: 6984 RVA: 0x00080651 File Offset: 0x0007E851
 private void AddCollectionContainer(CollectionContainer cc)
 {
     if (this.InternalList.Contains(cc))
     {
         throw new ArgumentException(SR.Get("CollectionContainerMustBeUniqueForComposite"), "cc");
     }
     CollectionChangedEventManager.AddHandler(cc, new EventHandler <NotifyCollectionChangedEventArgs>(this.OnContainedCollectionChanged));
 }
Esempio n. 18
0
        public DataSourceViewModel(Session session, DataSource model)
            : base(session)
        {
            Model = model;

            CollectionChangedEventManager.AddHandler(Model.Figures, OnFiguresChanged);
            OnFiguresChanged(null, null);
        }
Esempio n. 19
0
 /// <summary>Initializes a new instance of the ObservableListView class that represents a view of the specified list.</summary>
 /// <param name="originalList">The original list.</param>
 /// <param name="comparer">Optional, a custom comparer used to compare the items.</param>
 /// <param name="filter">Optional, a filter used for this list view.</param>
 /// <param name="sort">Optional, a sorting used for this list view.</param>
 /// <exception cref="ArgumentNullException">The argument originalCollection must not be null.</exception>
 public ObservableListView(IEnumerable <T> originalList, IEqualityComparer <T>?comparer, Predicate <T>?filter,
                           Func <IEnumerable <T>, IOrderedEnumerable <T> >?sort) : base(originalList, comparer, filter, sort, true)
 {
     originalObservableCollection = originalList as INotifyCollectionChanged;
     if (originalObservableCollection != null)
     {
         CollectionChangedEventManager.AddHandler(originalObservableCollection, OriginalCollectionChanged);
     }
 }
Esempio n. 20
0
 /// <summary>Initializes a new instance of the <see cref="SynchronizingCollection{T, TOriginal}"/> class.</summary>
 /// <param name="originalCollection">The original collection.</param>
 /// <param name="factory">The factory which is used to create new elements in this collection.</param>
 /// <exception cref="ArgumentNullException">The argument originalCollection must not be null.</exception>
 /// <exception cref="ArgumentNullException">The argument factory must not be null.</exception>
 public SynchronizingCollection(IEnumerable <TOriginal> originalCollection, Func <TOriginal, T> factory)
     : base(originalCollection, factory, true)
 {
     originalObservableCollection = originalCollection as INotifyCollectionChanged;
     if (originalObservableCollection != null)
     {
         CollectionChangedEventManager.AddHandler(originalObservableCollection, OriginalCollectionChanged);
     }
 }
Esempio n. 21
0
        private void RegisterChangeHandler()
        {
            if (myChildObservationCount == 0)
            {
                CollectionChangedEventManager.AddHandler(Children, OnChildrenChanged);
            }

            myChildObservationCount++;
        }
Esempio n. 22
0
 protected DocumentController(IFileService fileService)
 {
     if (fileService == null)
     {
         throw new ArgumentNullException(nameof(fileService));
     }
     this.fileService = fileService;
     PropertyChangedEventManager.AddHandler(fileService, FileServicePropertyChanged, "");
     CollectionChangedEventManager.AddHandler(fileService.Documents, DocumentsCollectionChanged);
 }
Esempio n. 23
0
        public MainViewModel(IMainView view, IShellService shellService, IFileService fileService)
            : base(view)
        {
            this.shellService = shellService;
            FileService       = fileService;
            DocumentViews     = new ObservableCollection <object>();

            CollectionChangedEventManager.AddHandler(DocumentViews, DocumentViewsCollectionChanged);
            PropertyChangedEventManager.AddHandler(fileService, FileServicePropertyChanged, "");
        }
Esempio n. 24
0
        public MainViewModel()
        {
            if (Dal == null)
            {
                return;
            }

            CollectionChangedEventManager.AddHandler(Dal.TraceLog, TraceLog_CollectionChanged);
            TraceLogString = new StringBuilder();
        }
        public static IObservable <ItemRemoved <T> > ObserveRemovedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemRemoved <T> >();

            var copy = new List <T>(list.Count + 8);

            foreach (var item in list)
            {
                copy.Add(item);
            }

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    copy.RemoveAt(e.OldStartingIndex);
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Replace:
                    copy[e.NewStartingIndex] = (T)e.NewItems[0];
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Move:
                    copy.RemoveAt(e.OldStartingIndex);
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = copy.Count - 1; i >= 0; --i)
                    {
                        subject.OnNext(new ItemRemoved <T>(copy[i], i));
                    }
                    copy.Clear();
                    foreach (var item in list)
                    {
                        copy.Add(item);
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
        private void OnRootChanged()
        {
            myTree.StateContainer.DataContext = Root;

            if (Root != null)
            {
                CollectionChangedEventManager.AddHandler((INotifyCollectionChanged)Root.Children, OnRootChildrenChanged);

                myTree.StateContainer.GetRoot().ShowChildrenCount = ShowChildrenCount;
            }
        }
Esempio n. 27
0
        private void OnProjectChanged()
        {
            if (myProjectHost.Project == null)
            {
                return;
            }

            CollectionChangedEventManager.AddHandler(myLutService.CurrenciesLut.Currencies, OnCurrenciesChanged);

            RaisePropertyChanged(nameof(CurrenciesLut));
            RaisePropertyChanged(nameof(Currencies));
        }
Esempio n. 28
0
 public ListToReadOnlyWrapper(IList <T> source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     _source = source;
     if (_source is INotifyCollectionChanged)
     {
         CollectionChangedEventManager.AddHandler(_source as INotifyCollectionChanged, HandleCollectionChanged);
     }
 }
Esempio n. 29
0
        // Hook up to a newly-added CollectionContainer
        private void AddCollectionContainer(CollectionContainer cc)
        {
            if (InternalList.Contains(cc))
            {
                throw new ArgumentException(SR.Get(SRID.CollectionContainerMustBeUniqueForComposite), "cc");
            }

            CollectionChangedEventManager.AddHandler(cc, OnContainedCollectionChanged);

#if DEBUG
            _hasRepeatedCollectionIsValid = false;
#endif
        }
        /// <summary>Listens to CollectionChanged events and notifies a list of other properties.</summary>
        protected void ForwardCollectionEvents(INotifyCollectionChanged source, params string[] notifyPropertyNames)
        {
            EventHandler <NotifyCollectionChangedEventArgs> func = (sender, e) =>
            {
                foreach (string p in notifyPropertyNames)
                {
                    Notify(p);
                }
            };

            funcReferences.Add(func);
            CollectionChangedEventManager.AddHandler(source, func);
        }