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> /// 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); }