Browse Source

Don't subscribe to inner observable if not active.

When subscribing to a `PropertySetterBindingInstance`, if the owner style is not active then there's no need to subscribe to the inner observable as this can cause resource lookups etc. Part of fixing #5027.
Steven Kirk 5 years ago
parent
commit
d8fbd95ef0
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/Avalonia.Styling/Styling/PropertySetterBindingInstance.cs

+ 7 - 1
src/Avalonia.Styling/Styling/PropertySetterBindingInstance.cs

@@ -92,6 +92,7 @@ namespace Avalonia.Styling
         {
             if (!_isActive)
             {
+                _innerSubscription ??= _binding.Observable.Subscribe(_inner);
                 _isActive = true;
                 PublishNext();
             }
@@ -102,6 +103,8 @@ namespace Avalonia.Styling
             if (_isActive)
             {
                 _isActive = false;
+                _innerSubscription?.Dispose();
+                _innerSubscription = null;
                 PublishNext();
             }
         }
@@ -148,7 +151,10 @@ namespace Avalonia.Styling
 
         protected override void Subscribed()
         {
-            _innerSubscription = _binding.Observable.Subscribe(_inner);
+            if (_isActive)
+            {
+                _innerSubscription = _binding.Observable.Subscribe(_inner);
+            }
         }
 
         protected override void Unsubscribed()