/// <summary> /// Sets the value of a direct property. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> private void SetDirectValueUnchecked <T>(DirectPropertyBase <T> property, BindingValue <T> value) { var p = AvaloniaPropertyRegistry.Instance.FindRegisteredDirect(this, property); if (p == null) { throw new ArgumentException($"Property '{property.Name} not registered on '{this.GetType()}"); } LogIfError(property, value); switch (value.Type) { case BindingValueType.UnsetValue: case BindingValueType.BindingError: var fallback = value.HasValue ? value : value.WithValue(property.GetUnsetValue(GetType())); property.InvokeSetter(this, fallback); break; case BindingValueType.DataValidationError: property.InvokeSetter(this, value); break; case BindingValueType.Value: case BindingValueType.BindingErrorWithFallback: case BindingValueType.DataValidationErrorWithFallback: property.InvokeSetter(this, value); break; } if (p.IsDataValidationEnabled) { UpdateDataValidation(property, value); } }
void IValueSink.ValueChanged <T>( StyledPropertyBase <T> property, BindingPriority priority, Optional <T> oldValue, BindingValue <T> newValue) { oldValue = oldValue.HasValue ? oldValue : GetInheritedOrDefault(property); newValue = newValue.HasValue ? newValue : newValue.WithValue(GetInheritedOrDefault(property)); LogIfError(property, newValue); if (!EqualityComparer <T> .Default.Equals(oldValue.Value, newValue.Value)) { RaisePropertyChanged(property, oldValue, newValue, priority); Logger.TryGet(LogEventLevel.Verbose)?.Log( LogArea.Property, this, "{Property} changed from {$Old} to {$Value} with priority {Priority}", property, oldValue, newValue, (BindingPriority)priority); } }