-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDEV-8025 - Adapt to different order Avalonia events are triggered
- Loading branch information
1 parent
0507f03
commit cd50dd5
Showing
2 changed files
with
6 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |