Skip to content

Commit

Permalink
RDEV-8025 - Adapt to different order Avalonia events are triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
heldergoncalves92 committed Dec 2, 2024
1 parent 0507f03 commit cd50dd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
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();
}
}
}
}

0 comments on commit cd50dd5

Please sign in to comment.