From 31e6bb4f72ce61ab69e4c78a04224674033807a9 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 24 Jul 2022 23:02:39 +0200 Subject: [PATCH] Fix evaluation in presence of multiple animation frames. --- src/Avalonia.Base/PropertyStore/ValueStore.cs | 3 ++ .../AvaloniaObjectTests_Binding.cs | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Avalonia.Base/PropertyStore/ValueStore.cs b/src/Avalonia.Base/PropertyStore/ValueStore.cs index 01fe597fb3..41f7b1711b 100644 --- a/src/Avalonia.Base/PropertyStore/ValueStore.cs +++ b/src/Avalonia.Base/PropertyStore/ValueStore.cs @@ -769,6 +769,9 @@ namespace Avalonia.PropertyStore { var frame = _frames[i]; + if (frame.Priority <= BindingPriority.LocalValue) + continue; + if (frame.IsActive && frame.TryGetEntry(property, out var entry) && entry.TryGetValue(out var v)) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs index 35b8c4c78f..cfb6338384 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs @@ -987,6 +987,35 @@ namespace Avalonia.Base.UnitTests subscription.Dispose(); } + [Fact] + public void Produces_Correct_Values_And_Base_Values_With_Multiple_Animation_Bindings() + { + var target = new Class1(); + var source1 = new BehaviorSubject>(12.2); + var source2 = new BehaviorSubject>(13.3); + + target.SetValue(Class1.QuxProperty, 11.1); + target.Bind(Class1.QuxProperty, source1, BindingPriority.Animation); + + Assert.Equal(12.2, target.GetValue(Class1.QuxProperty)); + Assert.Equal(11.1, target.GetBaseValue(Class1.QuxProperty)); + + target.Bind(Class1.QuxProperty, source2, BindingPriority.Animation); + + Assert.Equal(13.3, target.GetValue(Class1.QuxProperty)); + Assert.Equal(11.1, target.GetBaseValue(Class1.QuxProperty)); + + source2.OnCompleted(); + + Assert.Equal(12.2, target.GetValue(Class1.QuxProperty)); + Assert.Equal(11.1, target.GetBaseValue(Class1.QuxProperty)); + + source1.OnCompleted(); + + Assert.Equal(11.1, target.GetValue(Class1.QuxProperty)); + Assert.Equal(11.1, target.GetBaseValue(Class1.QuxProperty)); + } + /// /// Returns an observable that returns a single value but does not complete. ///