From 60c2e454371cfc8e9cd87772965fe3fce8337a42 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 6 Jul 2020 13:09:04 -0300 Subject: [PATCH] fix unsubscribe handler. --- src/Avalonia.Controls/ExperimentalAcrylicBorder.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/ExperimentalAcrylicBorder.cs b/src/Avalonia.Controls/ExperimentalAcrylicBorder.cs index 7306a8364f..0a01767a07 100644 --- a/src/Avalonia.Controls/ExperimentalAcrylicBorder.cs +++ b/src/Avalonia.Controls/ExperimentalAcrylicBorder.cs @@ -16,6 +16,8 @@ namespace Avalonia.Controls private readonly BorderRenderHelper _borderRenderHelper = new BorderRenderHelper(); + private IDisposable _subscription; + static ExperimentalAcrylicBorder() { AffectsRender( @@ -45,7 +47,7 @@ namespace Avalonia.Controls var tl = (e.Root as TopLevel); - tl.GetObservable(TopLevel.ActualTransparencyLevelProperty) + _subscription = tl.GetObservable(TopLevel.ActualTransparencyLevelProperty) .Subscribe(x => { switch (x) @@ -69,19 +71,20 @@ namespace Avalonia.Controls protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { base.OnDetachedFromVisualTree(e); - } + _subscription?.Dispose(); + } public override void Render(DrawingContext context) { - if(context.PlatformImpl is IDrawingContextWithAcrylicLikeSupport idc) + if (context.PlatformImpl is IDrawingContextWithAcrylicLikeSupport idc) { var cornerRadius = CornerRadius; idc.DrawRectangle( - Material, + Material, new RoundedRect( - new Rect(Bounds.Size), + new Rect(Bounds.Size), cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft)); }