/// <summary> /// Allows interested objects to be notified when this property changes. /// </summary> public override void RemoveValueChanged(object component, EventHandler handler) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } // If there's an event called <propertyname>Changed, we hooked the caller's // handler directly up to that on the component, so remove it now. EventDescriptor changedEvent = ChangedEventValue; if (changedEvent != null && changedEvent.EventType.IsInstanceOfType(handler)) { changedEvent.RemoveEventHandler(component, handler); } // Otherwise the base class added the handler to its ValueChanged // event for this component, so let the base class remove it now. else { base.RemoveValueChanged(component, handler); // Special case: If that was the LAST handler removed for this component, and the component implements // INotifyPropertyChanged, the property descriptor must STOP listening to the generic PropertyChanged event if (GetValueChangedHandler(component) == null) { EventDescriptor iPropChangedEvent = IPropChangedEventValue; iPropChangedEvent?.RemoveEventHandler(component, new PropertyChangedEventHandler(OnINotifyPropertyChanged)); } } }
public override void RemoveValueChanged(object component, EventHandler handler) { if (component == null) { throw new ArgumentNullException("component"); } if (handler == null) { throw new ArgumentNullException("handler"); } EventDescriptor changedEventValue = this.ChangedEventValue; if ((changedEventValue != null) && changedEventValue.EventType.IsInstanceOfType(handler)) { changedEventValue.RemoveEventHandler(component, handler); } else { base.RemoveValueChanged(component, handler); if (base.GetValueChangedHandler(component) == null) { EventDescriptor iPropChangedEventValue = this.IPropChangedEventValue; if (iPropChangedEventValue != null) { iPropChangedEventValue.RemoveEventHandler(component, new PropertyChangedEventHandler(this.OnINotifyPropertyChanged)); } } } }
/// <summary> /// Returns an observable sequence of events from the specified <paramref name="event"/> descriptor. /// </summary> /// <param name="event">The descriptor from which to create an observable sequence of changed notifications.</param> /// <param name="source">The object to which the <paramref name="event"/> belongs.</param> /// <returns>An observable sequence of events.</returns> public static IObservable <EventPattern <EventArgs> > EventRaised( this EventDescriptor @event, object source) { Contract.Requires(@event != null); Contract.Requires(source != null); Contract.Ensures(Contract.Result <IObservable <EventPattern <EventArgs> > >() != null); return(@event.EventType == typeof(EventHandler) ? Observable.FromEventPattern <EventHandler, EventArgs>( handler => handler.Invoke, handler => @event.AddEventHandler(source, handler), handler => @event.RemoveEventHandler(source, handler)) : new EventProxyObservable(source, @event)); }