Пример #1
0
        /// <summary>
        ///     Removes the specified observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        public void Remove(ICanExecuteChangedObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            if (!this.dictionary.TryGetValue(observer, out var handler))
            {
                return;
            }

            CommandManager.RequerySuggested -= handler;
            this.dictionary.Remove(observer);
            observer.RaisePropertyChanged();
        }
Пример #2
0
        /// <summary>
        ///     Removes the specified changedObserver.
        /// </summary>
        /// <param name="changedObserver">The changedObserver.</param>
        public void Remove([NotNull] ICanExecuteChangedObserver changedObserver)
        {
            if (changedObserver == null)
            {
                throw new ArgumentNullException(nameof(changedObserver));
            }

            if (!this.observables.TryGetValue(changedObserver, out var handler))
            {
                return;
            }

            this.Update -= handler;
            this.observables.Remove(changedObserver);
            changedObserver.RaisePropertyChanged();
        }
Пример #3
0
        /// <summary>
        /// Adds the specified observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        /// <exception cref="ArgumentNullException">observer is null.</exception>
        public void Add(ICanExecuteChangedObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            if (this.dictionary.TryGetValue(observer, out _))
            {
                return;
            }

            void Handler(object sender, EventArgs args) => observer.RaisePropertyChanged();

            this.dictionary.Add(observer, Handler);
            CommandManager.RequerySuggested += Handler;
        }
Пример #4
0
        /// <summary>
        ///     Adds the specified changedObserver.
        /// </summary>
        /// <param name="changedObserver">The changedObserver.</param>
        public void Add([NotNull] ICanExecuteChangedObserver changedObserver)
        {
            if (changedObserver == null)
            {
                throw new ArgumentNullException(nameof(changedObserver));
            }

            if (this.observables.TryGetValue(changedObserver, out _))
            {
                return;
            }

            void Handler() => changedObserver.RaisePropertyChanged();

            this.observables.Add(changedObserver, Handler);
            this.Update += Handler;
        }