void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent = false) { object original = context.Value; bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0; bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0; bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0; bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0; bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original); if (!silent && (!same || raiseOnEqual)) { property.PropertyChanging?.Invoke(this, original, value); OnPropertyChanging(property.PropertyName); } if (!same || raiseOnEqual) { context.Value = value; } context.Attributes &= ~BindableContextAttributes.IsDefaultValue; context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated; if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources) { RemoveDynamicResource(property); } BindingBase binding = context.Binding; if (binding != null) { if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay) { RemoveBinding(property, context); binding = null; } } if (!silent && (!same || raiseOnEqual)) { if (binding != null && !currentlyApplying) { _applying = true; binding.Apply(true); _applying = false; } OnPropertyChanged(property.PropertyName); property.PropertyChanged?.Invoke(this, original, value); } }
void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false) { object original = context.Value; bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0; bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0; bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0; bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0; bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original); if (!silent && (!same || raiseOnEqual)) { property.PropertyChanging?.Invoke(this, original, value); OnPropertyChanging(property.PropertyName); } if (!same || raiseOnEqual) { context.Value = value; } context.Attributes &= ~BindableContextAttributes.IsDefaultValue; context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated; if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources) { RemoveDynamicResource(property); } BindingBase binding = context.Binding; if (binding != null) { if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay) { RemoveBinding(property, context); binding = null; } } PropertyToGroup.TryGetValue(property, out HashSet <BindableProperty> propertyGroup); if (!silent) { if ((!same || raiseOnEqual)) { property.PropertyChanged?.Invoke(this, original, value); if (binding != null && !currentlyApplying) { applying = true; binding.Apply(true); applying = false; } OnPropertyChanged(property.PropertyName); if (null != propertyGroup) { foreach (var relativeProperty in propertyGroup) { if (relativeProperty != property) { var relativeContext = GetOrCreateContext(relativeProperty); var relativeBinding = relativeContext.Binding; if (null != relativeBinding) { applying = true; relativeBinding.Apply(true); applying = false; } OnPropertyChanged(relativeProperty.PropertyName); } } } } else if (true == same && true == forceSendChangeSignal) { if (binding != null && !currentlyApplying) { applying = true; binding.Apply(true); applying = false; } OnPropertyChanged(property.PropertyName); if (null != propertyGroup) { foreach (var relativeProperty in propertyGroup) { if (relativeProperty != property) { var relativeContext = GetOrCreateContext(relativeProperty); var relativeBinding = relativeContext.Binding; if (null != relativeBinding) { applying = true; relativeBinding.Apply(true); applying = false; } OnPropertyChanged(relativeProperty.PropertyName); } } } } OnPropertyChangedWithData(property); } }