public AddValueChanged ( object component, EventHandler handler ) : void | ||
component | object | |
handler | EventHandler | |
리턴 | void |
private EventMonitor(object instance, PropertyDescriptor property) { property.AddValueChanged(instance, (sender, e) => { count++; }); }
/// <summary> /// This function asigns a source and property to this viewmodel. /// </summary> /// <param name="source">The source.</param> /// <param name="property">The Property.</param> public virtual void Initialize(object source, PropertyDescriptor property) { Source = source; Property = property; Property.AddValueChanged(source, delegate { OnValueChanged(); }); }
protected override void Arrange() { base.Arrange(); traceOutputOptions = TraceListener.Property("TraceOutputOptions"); componentModelTraceOutputOptions = TraceListenerTypeDescriptor.GetProperties().OfType<PropertyDescriptor>().Where(x => x.Name == "TraceOutputOptions").First(); expirationPollFrequencyChanged = false; componentModelTraceOutputOptions.AddValueChanged(TraceListenerTypeDescriptor, new EventHandler((sender, args) => expirationPollFrequencyChanged = true)); }
protected override void Arrange() { base.Arrange(); expirationPollFrequency = CacheManager.Property("ExpirationPollFrequencyInSeconds"); componentModelExpirationPollFrequency = CacheManagerTypeDescriptor.GetProperties().OfType<PropertyDescriptor>().Where(x => x.Name == "ExpirationPollFrequencyInSeconds").First(); expirationPollFrequencyChanged = false; componentModelExpirationPollFrequency.AddValueChanged(CacheManagerTypeDescriptor, new EventHandler((sender, args) => expirationPollFrequencyChanged = true)); }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="descriptor"></param> /// <param name="owner"></param> public Property(object instance, PropertyDescriptor descriptor, PropertyEditor owner) : base(owner) { Instance = instance; Descriptor = descriptor; Name = descriptor.Name; Header = descriptor.DisplayName; ToolTip = descriptor.Description; // todo: is this ok? could it be a weak event? Descriptor.AddValueChanged(Instance, InstancePropertyChanged); }
internal override void SetDataSource(Object dataSource) { if (this.dataSource != null && !String.IsNullOrEmpty(this.propName)) { propInfo.RemoveValueChanged(this.dataSource, new EventHandler(PropertyChanged)); propInfo = null; } this.dataSource = dataSource; if (this.dataSource != null && !String.IsNullOrEmpty(this.propName)) { propInfo = TypeDescriptor.GetProperties(dataSource).Find(propName, true); if (propInfo == null) throw new ArgumentException(SR.GetString(SR.PropertyManagerPropDoesNotExist, propName, dataSource.ToString())); propInfo.AddValueChanged(dataSource, new EventHandler(PropertyChanged)); } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItem"/> class. /// </summary> public PropertyItem(PropertyDescriptor property, object instance) { Property = property; Instance = instance; ResetCommand = new Command<object>(ResetValue, CanResetValue); EditBindingCommand = new Command<object>(ShowBindingEditor, o => !property.IsReadOnly); EditResourceCommand = new Command<object>(ShowResourceEditor, o => !property.IsReadOnly); _propertySortInfo = PropertySorter.GetSortInfo(property); _markupObject = MarkupWriter.GetMarkupObjectFor(Instance); property.AddValueChanged(instance, OnValueChanged); _dpd = DependencyPropertyDescriptor.FromProperty(property); }
/// <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))); }
public ComponentChangeDispatcher(IServiceProvider serviceProvider, object component, PropertyDescriptor propertyDescriptor) { this.serviceProvider = serviceProvider; this.component = component; this.property = propertyDescriptor; IComponentChangeService service = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service != null) { try { this.newValue = this.oldValue = propertyDescriptor.GetValue(component); propertyDescriptor.AddValueChanged(component, new EventHandler(this.OnValueChanged)); service.OnComponentChanging(component, propertyDescriptor); } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw exception; } } } }
/// <summary> /// Constructor</summary> /// <param name="manager">The value changed event manager</param> /// <param name="source">The source of the value changed event</param> /// <param name="pd">The property descriptor of the value that changed</param> public ValueChangedRecord(ValueChangedEventManager manager, object source, PropertyDescriptor pd) { // keep a strong reference to the source. Normally we avoid this, but // it's OK here since its scope is exactly the same as the strong reference // held by the PD: begins with pd.AddValueChanged, ends with // pd.RemoveValueChanged. This ensures that we _can_ call RemoveValueChanged // even in cases where the source implements value-semantics (which // confuses the PD - see 795205). m_manager = manager; m_source = new WeakReference(source); m_pd = pd; m_eventArgs = new ValueChangedEventArgs(pd); pd.AddValueChanged(source, new EventHandler(OnValueChanged)); }
public ComponentChangeDispatcher(IServiceProvider serviceProvider, object component, PropertyDescriptor propertyDescriptor) { this.serviceProvider = serviceProvider; this.component = component; this.property = propertyDescriptor; IComponentChangeService changeService = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (changeService != null) { try { newValue = oldValue = propertyDescriptor.GetValue(component); propertyDescriptor.AddValueChanged(component, new EventHandler(OnValueChanged)); changeService.OnComponentChanging(component, propertyDescriptor); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) return; throw coEx; } } }
/// <summary> /// Subscribes to the ValueChanged event. /// </summary> /// <param name="descriptor"> /// The descriptor. /// </param> /// <param name="handler"> /// The handler. /// </param> protected void SubscribeValueChanged(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.AddValueChanged(this.GetPropertyOwner(descriptor, item), handler); } } else { descriptor.AddValueChanged(this.GetPropertyOwner(descriptor, this.Instance), handler); } }
internal void CheckBinding() { // At design time, don't check anything. // if (owner != null && owner.BindableComponent != null && owner.ControlAtDesignTime()) { return; } // force Column to throw if it's currently a bad column. //DataColumn tempColumn = this.Column; // remove propertyChangedNotification when this binding is deleted if (this.owner.BindingManagerBase != null && this.fieldInfo != null && this.owner.BindingManagerBase.IsBinding && !(this.owner.BindingManagerBase is CurrencyManager)) { fieldInfo.RemoveValueChanged(owner.BindingManagerBase.Current, new EventHandler(PropValueChanged)); } if (owner != null && owner.BindingManagerBase != null && owner.BindableComponent != null && owner.ComponentCreated && this.IsDataSourceInitialized) { string dataField = dataMember.BindingField; fieldInfo = owner.BindingManagerBase.GetItemProperties().Find(dataField, true); if (owner.BindingManagerBase.DataSource != null && fieldInfo == null && dataField.Length > 0) { throw new ArgumentException(SR.GetString(SR.ListBindingBindField, dataField), "dataMember"); } // Do not add propertyChange notification if // the fieldInfo is null // // we add an event handler to the dataSource in the BindingManagerBase because // if the binding is of the form (Control, ControlProperty, DataSource, Property1.Property2.Property3) // then we want to get notification from Current.Property1.Property2 and not from DataSource // when we get the backEnd notification we push the new value into the Control's property // if (fieldInfo != null && owner.BindingManagerBase.IsBinding && !(this.owner.BindingManagerBase is CurrencyManager)) { fieldInfo.AddValueChanged(this.owner.BindingManagerBase.Current, new EventHandler(PropValueChanged)); } } else { fieldInfo = null; } }