internal void OnPropertyUnboundExternally(PropertyBinding binding, RadObject boundObject) { if (this.IsDisposing) { return; } RadPropertyValue entry = this.propertyValues.GetEntry(binding.SourceProperty, false); if (entry == null) { return; } entry.BeginUpdate(true, false); entry.RemoveBoundObject(boundObject); if ((binding.BindingOptions & PropertyBindingOptions.TwoWay) == PropertyBindingOptions.TwoWay) { int num1 = (int)this.ResetValueCore(entry, ValueResetFlags.TwoWayBindingLocal); } if ((binding.BindingOptions & PropertyBindingOptions.PreserveAsLocalValue) == PropertyBindingOptions.PreserveAsLocalValue) { entry.SetLocalValue(binding.GetValue()); } entry.EndUpdate(true, false); int num2 = (int)this.UpdateValueCore(entry); }
/// <summary> /// Gets notified that the specified object has unbound itself from a property of ours. /// </summary> /// <param name="boundObject"></param> /// <param name="binding"></param> internal void OnPropertyUnboundExternally(PropertyBinding binding, RadObject boundObject) { if (this.IsDisposing) { return; } RadPropertyValue propVal = this.propertyValues.GetEntry(binding.SourceProperty, false); if (propVal == null) { return; } propVal.BeginUpdate(true, false); //remove previously registered relations propVal.RemoveBoundObject(boundObject); if ((binding.BindingOptions & PropertyBindingOptions.TwoWay) == PropertyBindingOptions.TwoWay) { //reset the local value applied from the two-way binding this.ResetValueCore(propVal, ValueResetFlags.TwoWayBindingLocal); } if ((binding.BindingOptions & PropertyBindingOptions.PreserveAsLocalValue) == PropertyBindingOptions.PreserveAsLocalValue) { propVal.SetLocalValue(binding.GetValue()); } propVal.EndUpdate(true, false); this.UpdateValueCore(propVal); }
public ValueUpdateResult BindProperty( RadProperty propertyToBind, RadObject sourceObject, RadProperty sourceProperty, PropertyBindingOptions options) { if (sourceObject == null) { throw new ArgumentNullException("Binding source object"); } if (sourceObject.IsDisposing || sourceObject.IsDisposed) { return(ValueUpdateResult.NotUpdated); } RadPropertyValue entry = this.propertyValues.GetEntry(propertyToBind, true); if (entry.PropertyBinding != null) { entry.BeginUpdate(true, false); int num = (int)this.ResetValueCore(entry, ValueResetFlags.Binding); entry.EndUpdate(true, false); } PropertyBinding binding = new PropertyBinding(sourceObject, propertyToBind, sourceProperty, options); ValueUpdateResult valueUpdateResult = this.SetValueCore(entry, (object)binding, (object)null, ValueSource.PropertyBinding); if ((options & PropertyBindingOptions.NoChangeNotify) == (PropertyBindingOptions)0) { sourceObject.OnPropertyBoundExternally(binding, this); } return(valueUpdateResult); }
protected internal virtual ValueUpdateResult ResetValueCore( RadPropertyValue propVal, ValueResetFlags flags) { if (flags == ValueResetFlags.None) { return(ValueUpdateResult.NotUpdated); } object currentValue = propVal.GetCurrentValue(false); ValueSource valueSource = propVal.ValueSource; RadPropertyValue source = (RadPropertyValue)null; if (!propVal.IsCompositionLocked) { source = new RadPropertyValue(propVal); } propVal.BeginUpdate(true, false); if ((flags & ValueResetFlags.Animation) == ValueResetFlags.Animation) { int num1 = (int)this.SetValueCore(propVal, (object)null, (object)null, ValueSource.Animation); } if ((flags & ValueResetFlags.Local) == ValueResetFlags.Local) { int num2 = (int)this.SetValueCore(propVal, (object)null, RadProperty.UnsetValue, ValueSource.Local); } if ((flags & ValueResetFlags.DefaultValueOverride) == ValueResetFlags.DefaultValueOverride) { int num3 = (int)this.SetValueCore(propVal, (object)null, RadProperty.UnsetValue, ValueSource.DefaultValue); } if ((flags & ValueResetFlags.Binding) == ValueResetFlags.Binding) { int num4 = (int)this.SetValueCore(propVal, (object)null, (object)null, ValueSource.PropertyBinding); } if ((flags & ValueResetFlags.TwoWayBindingLocal) == ValueResetFlags.TwoWayBindingLocal) { int num5 = (int)this.SetValueCore(propVal, (object)null, RadProperty.UnsetValue, ValueSource.LocalFromBinding); } if ((flags & ValueResetFlags.Style) == ValueResetFlags.Style) { int num6 = (int)this.SetValueCore(propVal, (object)null, (object)null, ValueSource.Style); } if ((flags & ValueResetFlags.Inherited) == ValueResetFlags.Inherited) { int num7 = (int)this.SetValueCore(propVal, (object)null, RadProperty.UnsetValue, ValueSource.Inherited); } propVal.EndUpdate(true, false); if (propVal.IsCompositionLocked) { return(ValueUpdateResult.Updating); } ValueUpdateResult valueUpdateResult = this.RaisePropertyNotifications(propVal, currentValue, propVal.GetCurrentValue(true), valueSource); if (valueUpdateResult == ValueUpdateResult.Canceled) { propVal.Copy(source); } source?.Dispose(); return(valueUpdateResult); }
/// <summary> /// Binds the specified property to a property of the provided binding source object. /// </summary> /// <param name="propertyToBind">Our property that is about to be bound.</param> /// <param name="sourceObject">The object to which source property belongs.</param> /// <param name="sourceProperty">The property to which we will bind.</param> /// <param name="options">Additional options, specifying the binding operation.</param> public ValueUpdateResult BindProperty(RadProperty propertyToBind, RadObject sourceObject, RadProperty sourceProperty, PropertyBindingOptions options) { if (sourceObject == null) { throw new ArgumentNullException("Binding source object"); } if (sourceObject.IsDisposing || sourceObject.IsDisposed) { return(ValueUpdateResult.NotUpdated); //throw new ObjectDisposedException("Binding source object"); } RadPropertyValue propVal = this.propertyValues.GetEntry(propertyToBind, true); //remove previous binding (if any) if (propVal.PropertyBinding != null) { //lock subsequent value updates propVal.BeginUpdate(true, false); this.ResetValueCore(propVal, ValueResetFlags.Binding); propVal.EndUpdate(true, false); } //create a new binding PropertyBinding binding = new PropertyBinding(sourceObject, propertyToBind, sourceProperty, options); //apply binding ValueUpdateResult result = this.SetValueCore(propVal, binding, null, ValueSource.PropertyBinding); if ((options & PropertyBindingOptions.NoChangeNotify) == 0) { //register ourselves as bound for source's property sourceObject.OnPropertyBoundExternally(binding, this); } return(result); }
protected virtual ValueUpdateResult SetValueCore( RadPropertyValue propVal, object propModifier, object newValue, ValueSource source) { if (this.GetBitState(1L) || this.GetBitState(2L)) { return(ValueUpdateResult.Canceled); } object currentValue = propVal.GetCurrentValue(false); ValueSource valueSource = propVal.ValueSource; RadPropertyValue source1 = (RadPropertyValue)null; bool isUpdatingValue = propVal.IsUpdatingValue; if (!propVal.IsCompositionLocked && this.IsPropertyCancelable(propVal.Metadata)) { source1 = new RadPropertyValue(propVal); } propVal.BeginUpdate(true, true); switch (source) { case ValueSource.DefaultValue: case ValueSource.DefaultValueOverride: propVal.SetDefaultValueOverride(newValue); break; case ValueSource.Inherited: propVal.InvalidateInheritedValue(); break; case ValueSource.Style: if (!isUpdatingValue) { this.RemoveAnimation(propVal); } propVal.SetStyle((IPropertySetting)propModifier); break; case ValueSource.Local: propVal.SetLocalValue(newValue); break; case ValueSource.PropertyBinding: if (!isUpdatingValue) { this.RemoveBinding(propVal); } propVal.SetBinding((PropertyBinding)propModifier); break; case ValueSource.LocalFromBinding: propVal.SetLocalValueFromBinding(newValue); break; case ValueSource.Animation: if (!isUpdatingValue) { this.RemoveAnimation(propVal); } propVal.SetAnimation((AnimatedPropertySetting)propModifier); break; } propVal.EndUpdate(true, true); if (propVal.IsCompositionLocked) { return(ValueUpdateResult.Updating); } ValueUpdateResult valueUpdateResult = this.RaisePropertyNotifications(propVal, currentValue, propVal.GetCurrentValue(true), valueSource); if (valueUpdateResult == ValueUpdateResult.Canceled && source1 != null) { propVal.Copy(source1); } source1?.Dispose(); return(valueUpdateResult); }
/// <summary> /// Resets the specified property value, using the provided reset flags. /// </summary> /// <param name="propVal"></param> /// <param name="flags"></param> /// <returns>The result of the operation.</returns> protected internal virtual ValueUpdateResult ResetValueCore(RadPropertyValue propVal, ValueResetFlags flags) { //no flags are specified if (flags == ValueResetFlags.None) { return(ValueUpdateResult.NotUpdated); } object oldValue = propVal.GetCurrentValue(false); ValueSource oldSource = propVal.ValueSource; RadPropertyValue oldState = null; //check whether we are in nested update block if (!propVal.IsCompositionLocked) { //create a copy of the current property value oldState = new RadPropertyValue(propVal); } propVal.BeginUpdate(true, false); //update property value as specified by the provided flags if ((flags & ValueResetFlags.Animation) == ValueResetFlags.Animation) { this.SetValueCore(propVal, null, null, ValueSource.Animation); } if ((flags & ValueResetFlags.Local) == ValueResetFlags.Local) { this.SetValueCore(propVal, null, RadProperty.UnsetValue, ValueSource.Local); } if ((flags & ValueResetFlags.DefaultValueOverride) == ValueResetFlags.DefaultValueOverride) { this.SetValueCore(propVal, null, RadProperty.UnsetValue, ValueSource.DefaultValue); } if ((flags & ValueResetFlags.Binding) == ValueResetFlags.Binding) { this.SetValueCore(propVal, null, null, ValueSource.PropertyBinding); } if ((flags & ValueResetFlags.TwoWayBindingLocal) == ValueResetFlags.TwoWayBindingLocal) { this.SetValueCore(propVal, null, RadProperty.UnsetValue, ValueSource.LocalFromBinding); } if ((flags & ValueResetFlags.Style) == ValueResetFlags.Style) { this.SetValueCore(propVal, null, null, ValueSource.Style); } if ((flags & ValueResetFlags.Inherited) == ValueResetFlags.Inherited) { this.SetValueCore(propVal, null, RadProperty.UnsetValue, ValueSource.Inherited); } propVal.EndUpdate(true, false); if (propVal.IsCompositionLocked) { return(ValueUpdateResult.Updating); } ValueUpdateResult result = this.RaisePropertyNotifications(propVal, oldValue, propVal.GetCurrentValue(true), oldSource); if (result == ValueUpdateResult.Canceled) { //restore previous state as operation was canceled propVal.Copy(oldState); } return(result); }
/// <summary> /// Performs the core logic of updating property value. /// </summary> /// <param name="propVal">The property value structure, holding property information.</param> /// <param name="propModifier">Additional modifier, like IPropertySetting</param> /// <param name="newValue">The actual new value to be set, valid for Local and DefaultValue sources.</param> /// <param name="source">Specifies the source of the provided new value.</param> /// <returns>The result of the operation.</returns> protected virtual ValueUpdateResult SetValueCore(RadPropertyValue propVal, object propModifier, object newValue, ValueSource source) { //do not set anything while disposing if (this.GetBitState(DisposingStateKey) || this.GetBitState(DisposedStateKey)) { return(ValueUpdateResult.Canceled); } object oldValue = propVal.GetCurrentValue(false); ValueSource oldSource = propVal.ValueSource; RadPropertyValue oldPropState = null; bool updatingValue = propVal.IsUpdatingValue; if (!propVal.IsCompositionLocked && this.IsPropertyCancelable(propVal.Metadata)) { //create a copy of the current property value //so that we may restore it later if property change is not accepted oldPropState = new RadPropertyValue(propVal); } //perform value update propVal.BeginUpdate(true, true); switch (source) { case ValueSource.Animation: if (!updatingValue) { this.RemoveAnimation(propVal); } propVal.SetAnimation((AnimatedPropertySetting)propModifier); break; case ValueSource.DefaultValue: case ValueSource.DefaultValueOverride: propVal.SetDefaultValueOverride(newValue); break; case ValueSource.Local: propVal.SetLocalValue(newValue); break; case ValueSource.LocalFromBinding: propVal.SetLocalValueFromBinding(newValue); break; case ValueSource.PropertyBinding: if (!updatingValue) { RemoveBinding(propVal); } propVal.SetBinding((PropertyBinding)propModifier); break; case ValueSource.Style: if (!updatingValue) { this.RemoveAnimation(propVal); } propVal.SetStyle((IPropertySetting)propModifier); break; case ValueSource.Inherited: propVal.InvalidateInheritedValue(); break; default: Debug.Assert(false, "Invalid value source"); break; } propVal.EndUpdate(true, true); //are we still in a process of updating? if (propVal.IsCompositionLocked) { return(ValueUpdateResult.Updating); } ValueUpdateResult result = this.RaisePropertyNotifications(propVal, oldValue, propVal.GetCurrentValue(true), oldSource); if (result == ValueUpdateResult.Canceled && oldPropState != null) { //restore previous state as operation was canceled propVal.Copy(oldPropState); } return(result); }