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
Ejemplo n.º 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)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unsubscribes the value changed event.
        /// </summary>
        /// <param name="descriptor">
        /// The descriptor.
        /// </param>
        /// <param name="handler">
        /// The handler.
        /// </param>
        protected void UnsubscribeValueChanged(PropertyDescriptor descriptor, EventHandler handler)
        {
            if (this.IsEnumerable)
            {
                var list = this.Instance as IEnumerable;
                if (list == null)
                {
                    throw new InvalidOperationException("Instance should be a list.");
                }

                foreach (var item in list)
                {
                    descriptor.RemoveValueChanged(this.GetPropertyOwner(descriptor, item), handler);
                }
            }
            else
            {
                descriptor.RemoveValueChanged(this.GetPropertyOwner(descriptor, this.Instance), handler);
            }
        }