From 90fb76f364605928ef124e9e875066a4bcc10a60 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 23 Nov 2020 15:50:11 +0100 Subject: [PATCH] Prevent exceptions when removing styles. When `_target.Owner` was null, the resource observable produced a `null` which may not be valid for the target property, resulting in an exception . Although the exception is caught, it slows things down. --- src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs index 250274c39b..fedd3469e6 100644 --- a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs +++ b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs @@ -147,13 +147,16 @@ namespace Avalonia.Controls { if (_target.Owner is object) { - observer.OnNext(Convert(_target.Owner?.FindResource(_key))); + observer.OnNext(Convert(_target.Owner.FindResource(_key))); } } private void PublishNext() { - PublishNext(Convert(_target.Owner?.FindResource(_key))); + if (_target.Owner is object) + { + PublishNext(Convert(_target.Owner.FindResource(_key))); + } } private void OwnerChanged(object sender, EventArgs e)