public void GetProperties_SetValueOutOfRangeWithHandler_CallsValueChanged() { var array = new int[] { 1, 2, 3 }; var smallerArray = new int[] { 1, 2 }; PropertyDescriptor property = Converter.GetProperties(array)[2]; int callCount = 0; EventHandler handler = (sender, e) => { Assert.Same(smallerArray, sender); Assert.Same(EventArgs.Empty, e); callCount++; }; // With handler. property.AddValueChanged(smallerArray, handler); property.SetValue(smallerArray, 0); Assert.Equal(new int[] { 1, 2 }, smallerArray); Assert.Equal(new int[] { 1, 2, 3 }, array); Assert.Equal(1, callCount); // Remove handler. property.RemoveValueChanged(smallerArray, handler); property.SetValue(smallerArray, 1); Assert.Equal(new int[] { 1, 2 }, smallerArray); Assert.Equal(new int[] { 1, 2, 3 }, array); Assert.Equal(1, callCount); }
private static void OnCustomSortCommandChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { // We only setup sorting for datagrids DataGrid dg = obj as DataGrid; if (dg == null) { return; } // Add an event handler for the sort event dg.Sorting += DataGridSorting; // Get the sort command ICommand command = GetCustomSortCommand(dg); foreach (var col in dg.Columns) { // Add an event handler to the SortDirection property PropertyDescriptor prop = TypeDescriptor.GetProperties(col)["SortDirection"]; prop.AddValueChanged(col, SortDirectionChanged); // Add the CustomSortCommand to the columns also DataGridAttachedProperties.SetCustomSortCommand(col, command); } }
/// <param name="designer"> The property designer. </param> public PropertyDesignerManager(object instance, PropertyDescriptor descriptor, IDesigner designer) { _designer = designer; _designer.Disposed += new EventHandler(DesignerDisposed); _designer.Service.OnRequestSave += new RequestHandler(DesignerRequestedSave); _descriptor = descriptor; _descriptor.AddValueChanged(instance, new EventHandler(PropertyChanged)); _instance = instance; IDisposableNotify localInstance = _instance as IDisposableNotify; if (localInstance != null) { localInstance.Disposed += new EventHandler(InstanceDisposed); } ISite site = ((IComponent)_instance).Site; if (site != null) { _service = (IDesignService)site.GetService(typeof(IDesignService)); _service.Dependants.Add(_designer.Service); } else { _service = null; } }
/// <summary> /// This is used to connect and disconnect the property changed event handlers /// </summary> /// <param name="connect">True to connect, false to disconnect</param> internal void WirePropChangedEvents(bool connect) { PropertyDescriptor propInfo = null; FieldInfo fi; if (rowSource != null) { BindingsCollection bc = this.BindingContext[rowSource].Bindings; // The bindings don't expose an event or anything else that notifies us when a bound field // changes. As such, we have to hack into the mechanism using Reflection. foreach (Binding b in bc) { fi = b.GetType().GetField("propInfo", BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null) { propInfo = (PropertyDescriptor)fi.GetValue(b); } if (propInfo != null) { if (connect) { propInfo.AddValueChanged(b.Control, Target_PropertyChanged); } else { propInfo.RemoveValueChanged(b.Control, Target_PropertyChanged); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItem"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="component">The component property belongs to.</param> /// <param name="descriptor">The property descriptor</param> public PropertyItem(PropertyGrid owner, object component, PropertyDescriptor descriptor) : this(null) { if (owner == null) { throw new ArgumentNullException("owner"); } if (component == null) { throw new ArgumentNullException("component"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } Owner = owner; Name = descriptor.Name; _component = component; _descriptor = descriptor; IsBrowsable = descriptor.IsBrowsable; _isReadOnly = descriptor.IsReadOnly; _description = descriptor.Description; _categoryName = descriptor.Category; _isLocalizable = descriptor.IsLocalizable; _metadata = new AttributesContainer(descriptor.Attributes); _descriptor.AddValueChanged(component, ComponentValueChanged); }
private EventMonitor(object instance, PropertyDescriptor property) { property.AddValueChanged(instance, (sender, e) => { count++; }); }
private static void OnScrollOnNewItemChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { ListBox listBox = dependencyObject as ListBox; if (listBox != null) { Boolean oldValue = (Boolean)e.OldValue; Boolean newValue = (Boolean)e.NewValue; if (newValue != oldValue) { PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"]; if (newValue) { listBox.Loaded += ListBox_Loaded; listBox.Unloaded += ListBox_Unloaded; itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged); } else { listBox.Loaded -= ListBox_Loaded; listBox.Unloaded -= ListBox_Unloaded; if (ListBoxBehaviors.Associations.ContainsKey(listBox)) { ListBoxBehaviors.Associations[listBox].Dispose(); } itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged); } } } }
public void AddValueChanged_WhenPropertyChanges_CallbackIsInvoked() { int callbackInvocationCount = 0; object actualSender = null; string actualValueInCallback = null; EventHandler callback = (s, _) => { callbackInvocationCount++; actualSender = s; actualValueInCallback = _viewModel.CommentTestAccessor; }; PropertyDescriptor pd = GetPropertyDescriptor("Comment"); pd.AddValueChanged(_viewModel, callback); var newPropertyValue = ArbitraryCommentValue; _viewModel.CommentTestAccessor = newPropertyValue; Assert.AreNotEqual(0, callbackInvocationCount, "The callback was not invoked."); Assert.AreEqual(1, callbackInvocationCount, "The callback should not be invoked more than once."); Assert.AreSame(_viewModel, actualSender, "The sender of the event handler should be the view model."); Assert.AreEqual(newPropertyValue, actualValueInCallback, "GetValue should already return the new property value in the callback."); }
internal void InitSummaryTable(Label title, DataGrid dataGrid, ComboBox columns) { TheDataGrid = dataGrid; TheSelectedColumns = columns; TheTitle = title; if (title != null) { TheTitle.Content = DEFAULT_TABLE_LABEL; } if (TheDataGrid != null) { TheDataGrid.Sorting += DataGrid_Sorting; // sort numbers descending PropertyDescriptor orderPd = DependencyPropertyDescriptor.FromProperty(DataGridColumn.DisplayIndexProperty, typeof(DataGridColumn)); foreach (var column in dataGrid.Columns) { orderPd.AddValueChanged(column, new EventHandler(ColumnDisplayIndexPropertyChanged)); } if (TheSelectedColumns != null) { TheShownColumns = DataGridUtil.LoadColumns(TheSelectedColumns, TheDataGrid); } } }
public static void OnScrollOnNewItemChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { ListBox listBox = d as ListBox; if (listBox == null) { return; } bool oldValue = (bool)e.OldValue, newValue = (bool)e.NewValue; if (newValue == oldValue) { return; } if (newValue) { listBox.Loaded += ListBox_Loaded; listBox.Unloaded += ListBox_Unloaded; PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"]; itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged); } else { listBox.Loaded -= ListBox_Loaded; listBox.Unloaded -= ListBox_Unloaded; if (Associations.ContainsKey(listBox)) { Associations[listBox].Dispose(); } PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"]; itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged); } }
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; } } }
private void SubscribeValueChanged() { foreach (object instance in Instances) { m_descriptor.AddValueChanged(instance, Instance_PropertyValueChanged); } }
public DescriptorAdapter(object target, PropertyDescriptor descriptor) { _target = target; _descriptor = descriptor; _valueChangedCallback = newValue => { }; _descriptor.AddValueChanged(target, OnValueChanged); }
public Matrix() { InitializeComponent(); PropertyDescriptor pdSL = DependencyPropertyDescriptor.FromProperty(Matrix.SwimLaneViewProperty, typeof(Matrix)); pdSL.AddValueChanged(this, new System.EventHandler(SwimLanePropertyChanged)); }
// Token: 0x06008DF6 RID: 36342 RVA: 0x0025AC58 File Offset: 0x00258E58 public ValueChangedRecord(ValueChangedEventManager manager, object source, PropertyDescriptor pd) { this._manager = manager; this._source = source; this._pd = pd; this._eventArgs = new ValueChangedEventArgs(pd); pd.AddValueChanged(source, new EventHandler(this.OnValueChanged)); }
public void SubscribeToValueChange(object obj) { if (_prop.SupportsChangeEvents) { _prop.AddValueChanged(obj, ValueChanged); _prevOb.Target = obj; } }
private static void OverridePropertyOnChanged(ToolBarTray toolBarTray, DependencyProperty property, EventHandler handler) { PropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, typeof(ToolBar)); foreach (var toolBar in toolBarTray.ToolBars) { propertyDescriptor.AddValueChanged(toolBar, handler); } }
/// <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(); }); }
public override void AddValueChanged(object component, EventHandler handler) { if (_parentPD != null) { component = _parentPD.GetValue(component); } _currentPD.AddValueChanged(component, handler); }
private static void OverrideColumnsPropertyOnChanged(DataGrid dataGrid, DependencyProperty property, EventHandler handler) { PropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, typeof(DataGridColumn)); foreach (DataGridColumn column in dataGrid.Columns) { propertyDescriptor.AddValueChanged(column, handler); } }
/// <summary> /// Subscribes to the ValueChanged event. /// </summary> protected void SubscribeValueChanged(PropertyDescriptor descriptor, EventHandler handler) { if (IsEnumerable) { var list = Instance as IEnumerable; if (list == null) { throw new InvalidOperationException("Instance should be a list."); } foreach (object item in list) { descriptor.AddValueChanged(GetPropertyOwner(descriptor, item), handler); } } else { descriptor.AddValueChanged(GetPropertyOwner(descriptor, Instance), handler); } }
//- - - - - - - - - - - - - - - - - - - - - - - - #endregion #region auto center Events //- - - - - - - - - - - - - - - - - - - - - - - - void CarouselPanel_Loaded(object sender, RoutedEventArgs e) { SurfaceScrollViewer ssv = ScrollOwner as SurfaceScrollViewer; if (ssv != null) { PropertyDescriptor prop = TypeDescriptor.GetProperties(typeof(SurfaceScrollViewer))["IsScrolling"]; prop.AddValueChanged(ssv, new EventHandler(this.ScrollEnded)); } }
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> /// Starts listenting to value changes by adding an event handler. /// </summary> private void AddValueChanged() { if (SourceObject == null || PropertyDescriptor == null) { return; } PropertyDescriptor.AddValueChanged(SourceObject, OnValueChanged); isListening = true; }
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)); }
private void RegisterLoad() { if (!AssociatedObject.IsLoaded || string.IsNullOrWhiteSpace(_screenHostAutoKey)) { return; } _timer.Tick += OnTimerTick; foreach (var column in AssociatedObject.Columns) { _propertyDescriptor.AddValueChanged(column, new EventHandler(OnColumnWidthPropertyChanged)); } }
/// <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); }
public void RaiseAddedValueChangedHandler() { var component = new DescriptorTestComponent(); var properties = TypeDescriptor.GetProperties(component.GetType()); PropertyDescriptor propertyDescriptor = properties.Find(nameof(component.Property), false); var handlerWasCalled = false; EventHandler valueChangedHandler = (_, __) => handlerWasCalled = true; propertyDescriptor.AddValueChanged(component, valueChangedHandler); propertyDescriptor.SetValue(component, int.MaxValue); Assert.True(handlerWasCalled); }
public void GetTypeDescriptorGetPropertiesWrappedPropertyDescriptor_AddValueChanged_Success() { var provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(ClassWithMetadataOnAnotherClass)); PropertyDescriptorCollection properties = provider.GetTypeDescriptor(typeof(ClassWithMetadataOnAnotherClass), null).GetProperties(); PropertyDescriptor descriptor = properties[nameof(ClassWithMetadataOnAnotherClass.FirstName)]; var component = new ClassWithMetadataOnAnotherClass(); int callCount = 0; EventHandler handler = (sender, e) => callCount++; descriptor.AddValueChanged(component, handler); descriptor.SetValue(component, "value"); Assert.Equal(1, callCount); }
public void RefreshDescriptors(PropertyDescriptor descriptor) { Name = descriptor.Name; _descriptor = descriptor; IsBrowsable = descriptor.IsBrowsable; _isReadOnly = descriptor.IsReadOnly; _description = descriptor.Description; CategoryName = descriptor.Category; IsLocalizable = descriptor.IsLocalizable; Metadata = new AttributesContainer(descriptor.Attributes); _descriptor.AddValueChanged(Component, ComponentValueChanged); }