Browse Source

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.
pull/5093/head
Steven Kirk 6 years ago
parent
commit
90fb76f364
  1. 7
      src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs

7
src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs

@ -147,13 +147,16 @@ namespace Avalonia.Controls
{ {
if (_target.Owner is object) if (_target.Owner is object)
{ {
observer.OnNext(Convert(_target.Owner?.FindResource(_key))); observer.OnNext(Convert(_target.Owner.FindResource(_key)));
} }
} }
private void PublishNext() 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) private void OwnerChanged(object sender, EventArgs e)

Loading…
Cancel
Save