Skip to content

RDEV-8025 - Adapt to different order Avalonia events are triggered #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PropertyGroup>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Version>3.120.7</Version>
<Version>3.120.8</Version>
<Authors>OutSystems</Authors>
<Product>WebViewControl</Product>
<Copyright>Copyright © OutSystems 2023</Copyright>
Expand Down
25 changes: 5 additions & 20 deletions WebViewControl.Avalonia/BaseControl.cs
Original file line number Diff line number Diff line change
@@ -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<RoutedEventArgs>)OnHostWindowClosed);
}
base.OnAttachedToLogicalTree(e);
}

protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) {
if (e.Root is Window window) {
window.RemoveHandler(Window.WindowClosedEvent, (EventHandler<RoutedEventArgs>)OnHostWindowClosed);
}
base.OnDetachedFromLogicalTree(e);
}

private void OnHostWindowClosed(object sender, RoutedEventArgs eventArgs) {
((Window)sender).RemoveHandler(Window.WindowClosedEvent, (EventHandler<RoutedEventArgs>)OnHostWindowClosed);
InternalDispose();
if (e.Root is Window w && w.PlatformImpl is null) {
// Window was closed.
InternalDispose();
}
}
}
}
Loading