diff --git a/Directory.Build.props b/Directory.Build.props index 015bc265..cc3e70cd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,7 +10,7 @@ 2.0.0.0 2.0.0.0 - 3.120.7 + 3.120.8 OutSystems WebViewControl Copyright © OutSystems 2023 diff --git a/WebViewControl.Avalonia/BaseControl.cs b/WebViewControl.Avalonia/BaseControl.cs index 77a6f9ac..78deb793 100644 --- a/WebViewControl.Avalonia/BaseControl.cs +++ b/WebViewControl.Avalonia/BaseControl.cs @@ -1,32 +1,17 @@ -using System; -using Avalonia.Controls; -using Avalonia.Interactivity; +using Avalonia.Controls; using Avalonia.LogicalTree; namespace WebViewControl { - public abstract class BaseControl : Control { - protected abstract void InternalDispose(); - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { - if (e.Root is Window window) { - // need to subscribe the event this way because close gets called after all elements get detached - window.AddHandler(Window.WindowClosedEvent, (EventHandler)OnHostWindowClosed); - } - base.OnAttachedToLogicalTree(e); - } - protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) { - if (e.Root is Window window) { - window.RemoveHandler(Window.WindowClosedEvent, (EventHandler)OnHostWindowClosed); - } base.OnDetachedFromLogicalTree(e); - } - private void OnHostWindowClosed(object sender, RoutedEventArgs eventArgs) { - ((Window)sender).RemoveHandler(Window.WindowClosedEvent, (EventHandler)OnHostWindowClosed); - InternalDispose(); + if (e.Root is Window w && w.PlatformImpl is null) { + // Window was closed. + InternalDispose(); + } } } }