From ead89805cd804de0994256219037b8adaef944c6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 20 Sep 2022 16:13:11 +0200 Subject: [PATCH] Fix inactive two-way setter bindings. Make two-way bindings in setters not write to source when inactive. --- .../PropertyStore/BindingEntryBase.cs | 18 +++++++++--------- .../Styling/PropertySetterBindingInstance.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Avalonia.Base/PropertyStore/BindingEntryBase.cs b/src/Avalonia.Base/PropertyStore/BindingEntryBase.cs index f81666a6ff..34b8048bbc 100644 --- a/src/Avalonia.Base/PropertyStore/BindingEntryBase.cs +++ b/src/Avalonia.Base/PropertyStore/BindingEntryBase.cs @@ -13,7 +13,6 @@ namespace Avalonia.PropertyStore { private static IDisposable s_creating = Disposable.Empty; private static IDisposable s_creatingQuiet = Disposable.Create(() => { }); - private readonly ValueFrame _frame; private IDisposable? _subscription; private bool _hasValue; private TValue? _value; @@ -23,7 +22,7 @@ namespace Avalonia.PropertyStore AvaloniaProperty property, IObservable> source) { - _frame = frame; + Frame = frame; Source = source; Property = property; } @@ -33,7 +32,7 @@ namespace Avalonia.PropertyStore AvaloniaProperty property, IObservable source) { - _frame = frame; + Frame = frame; Source = source; Property = property; } @@ -50,6 +49,7 @@ namespace Avalonia.PropertyStore public bool IsSubscribed => _subscription is not null; public AvaloniaProperty Property { get; } AvaloniaProperty IValueEntry.Property => Property; + protected ValueFrame Frame { get; } protected object Source { get; } public void Dispose() @@ -125,16 +125,16 @@ namespace Avalonia.PropertyStore _hasValue = false; _value = default; if (_subscription is not null) - _frame.Owner?.OnBindingValueCleared(Property, _frame.Priority); + Frame.Owner?.OnBindingValueCleared(Property, Frame.Priority); } } private void SetValue(BindingValue value) { - if (_frame.Owner is null) + if (Frame.Owner is null) return; - LoggingUtils.LogIfNecessary(_frame.Owner.Owner, Property, value); + LoggingUtils.LogIfNecessary(Frame.Owner.Owner, Property, value); if (value.HasValue) { @@ -143,21 +143,21 @@ namespace Avalonia.PropertyStore _value = value.Value; _hasValue = true; if (_subscription is not null && _subscription != s_creatingQuiet) - _frame.Owner?.OnBindingValueChanged(Property, _frame.Priority, value.Value); + Frame.Owner?.OnBindingValueChanged(Property, Frame.Priority, value.Value); } } else if (value.Type != BindingValueType.DoNothing) { ClearValue(); if (_subscription is not null && _subscription != s_creatingQuiet) - _frame.Owner?.OnBindingValueCleared(Property, _frame.Priority); + Frame.Owner?.OnBindingValueCleared(Property, Frame.Priority); } } private void BindingCompleted() { _subscription = null; - _frame.OnBindingCompleted(this); + Frame.OnBindingCompleted(this); } } } diff --git a/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs b/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs index 86a8b9c683..826b45582d 100644 --- a/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs +++ b/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs @@ -52,7 +52,7 @@ namespace Avalonia.Styling { if (e.Property == Property && e.Priority >= BindingPriority.LocalValue) { - //if (Frame.Owner is not null && !Frame.Owner.IsEvaluating) + if (Frame.Owner is not null && !Frame.Owner.IsEvaluating) ((IObserver)Source).OnNext(e.NewValue); } }