System.ComponentModel.PropertyDescriptor.RemoveValueChanged C# (CSharp) Method

RemoveValueChanged() public method

Allows interested objects to be notified when this property changes.
public RemoveValueChanged ( object component, EventHandler handler ) : void
component object
handler EventHandler
return void
        public virtual void RemoveValueChanged(object component, EventHandler handler)
        {
            if (component == null) throw new ArgumentNullException(nameof(component));
            if (handler == null) throw new ArgumentNullException(nameof(handler));

            if (_valueChangedHandlers != null)
            {
                EventHandler h = (EventHandler)_valueChangedHandlers[component];
                h = (EventHandler)Delegate.Remove(h, handler);
                if (h != null)
                {
                    _valueChangedHandlers[component] = h;
                }
                else
                {
                    _valueChangedHandlers.Remove(component);
                }
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Returns an observable sequence of property changed notifications from the
        /// specified <paramref name="property"/> descriptor.
        /// </summary>
        /// <param name="property">The descriptor from which to create an observable sequence of changed notifications.</param>
        /// <param name="source">The object to which the <paramref name="property"/> belongs.</param>
        /// <returns>An observable sequence of property changed notifications.</returns>
        /// <exception cref="ArgumentException">The specified property does not support change events.</exception>
        public static IObservable <EventPattern <PropertyChangedEventArgs> > PropertyChanged(
            this PropertyDescriptor property,
            object source)
        {
            Contract.Requires(property != null);
            Contract.Requires(source != null);
            Contract.Ensures(Contract.Result <IObservable <EventPattern <PropertyChangedEventArgs> > >() != null);

            if (!property.SupportsChangeEvents)
            {
                throw new ArgumentException(Errors.PropertyDoesNotSupportChangeEvents, "property");
            }

            return
                (from e in Observable.FromEventPattern <EventHandler, EventArgs>(
                     handler => handler.Invoke,
                     handler => property.AddValueChanged(source, handler),
                     handler => property.RemoveValueChanged(source, handler))
                 select new EventPattern <PropertyChangedEventArgs>(
                     e.Sender,
                     e.EventArgs as PropertyChangedEventArgs ?? new PropertyChangedEventArgs(property.Name)));
        }
All Usage Examples Of System.ComponentModel.PropertyDescriptor::RemoveValueChanged