From 9d051a6a64c6039bd8b075c7997468741a78acc8 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 21 Jun 2023 09:39:02 +0200 Subject: [PATCH 1/2] Added failing test for #11484. --- .../AvaloniaObjectTests_Coercion.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs index 42720cbb4c..e664829677 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs @@ -243,6 +243,19 @@ namespace Avalonia.Base.UnitTests Assert.Equal(new[] { 11 }, target.CoerceFooInvocations); } + [Fact] + public void Second_Coerce_Of_Default_Value_Is_Passed_Uncoerced_Value() + { + var target = new Class1(); + + target.MinFoo = 20; + target.CoerceFooInvocations.Clear(); + target.CoerceValue(Class1.FooProperty); + target.CoerceValue(Class1.FooProperty); + + Assert.Equal(new[] { 11, 11 }, target.CoerceFooInvocations); + } + [Fact] public void ClearValue_Respects_Coerced_Default_Value() { From a2d572e006cfd30eb6825f0cf3e33b55cef0e91e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 21 Jun 2023 09:43:28 +0200 Subject: [PATCH 2/2] Don't set uncoerced value to coerced default val. Fixes #11484 --- src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs b/src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs index 4518289335..a69d7b7094 100644 --- a/src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs +++ b/src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs @@ -216,7 +216,7 @@ namespace Avalonia.PropertyStore valueChanged = !EqualityComparer.Default.Equals(Value, v); Value = v; Priority = priority; - if (_uncommon is not null) + if (!isCoercedDefaultValue && _uncommon is not null) _uncommon._uncoercedValue = value; } @@ -225,7 +225,7 @@ namespace Avalonia.PropertyStore baseValueChanged = !EqualityComparer.Default.Equals(_baseValue, v); _baseValue = v; BasePriority = priority; - if (_uncommon is not null) + if (!isCoercedDefaultValue && _uncommon is not null) _uncommon._uncoercedBaseValue = value; }