Browse Source

Use correct newValue on inherited property change.

- `oldValue` was misnamed - it's the new value
- We calculated the new value and then didn't pass it to children for their property changed events: they were using the default value which may be wrong if the value is set further up the tree
pull/10858/head
Steven Kirk 4 years ago
parent
commit
683afe6e9f
  1. 12
      src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs
  2. 8
      src/Avalonia.Base/PropertyStore/ValueStore.cs

12
src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs

@ -140,24 +140,24 @@ namespace Avalonia.PropertyStore
var p = (StyledProperty<T>)property;
BindingPriority priority;
T oldValue;
T newValue;
if (property.Inherits && owner.TryGetInheritedValue(property, out var i))
{
oldValue = ((EffectiveValue<T>)i).Value;
newValue = ((EffectiveValue<T>)i).Value;
priority = BindingPriority.Inherited;
}
else
{
oldValue = _metadata.DefaultValue;
newValue = _metadata.DefaultValue;
priority = BindingPriority.Unset;
}
if (!EqualityComparer<T>.Default.Equals(oldValue, Value))
if (!EqualityComparer<T>.Default.Equals(newValue, Value))
{
owner.Owner.RaisePropertyChanged(p, Value, oldValue, priority, true);
owner.Owner.RaisePropertyChanged(p, Value, newValue, priority, true);
if (property.Inherits)
owner.OnInheritedEffectiveValueDisposed(p, Value);
owner.OnInheritedEffectiveValueDisposed(p, Value, newValue);
}
if (ValueEntry?.GetDataValidationState(out _, out _) ??

8
src/Avalonia.Base/PropertyStore/ValueStore.cs

@ -419,7 +419,9 @@ namespace Avalonia.PropertyStore
ReevaluateEffectiveValue(property, current);
}
else
{
ReevaluateEffectiveValues();
}
}
/// <summary>
@ -481,7 +483,8 @@ namespace Avalonia.PropertyStore
/// </summary>
/// <param name="property">The property whose value changed.</param>
/// <param name="oldValue">The old value of the property.</param>
public void OnInheritedEffectiveValueDisposed<T>(StyledProperty<T> property, T oldValue)
/// <param name="newValue">The new value of the property.</param>
public void OnInheritedEffectiveValueDisposed<T>(StyledProperty<T> property, T oldValue, T newValue)
{
Debug.Assert(property.Inherits);
@ -489,12 +492,11 @@ namespace Avalonia.PropertyStore
if (children is not null)
{
var defaultValue = property.GetDefaultValue(Owner.GetType());
var count = children.Count;
for (var i = 0; i < count; ++i)
{
children[i].GetValueStore().OnAncestorInheritedValueChanged(property, oldValue, defaultValue);
children[i].GetValueStore().OnAncestorInheritedValueChanged(property, oldValue, newValue);
}
}
}

Loading…
Cancel
Save