|
14 | 14 | using Avalonia.Platform;
|
15 | 15 | using Avalonia.VisualTree;
|
16 | 16 | using Avalonia.Media;
|
| 17 | +using Avalonia.Interactivity; |
17 | 18 |
|
18 | 19 | namespace Avalonia.Controls.Primitives
|
19 | 20 | {
|
@@ -460,13 +461,13 @@ public void Open()
|
460 | 461 | SubscribeToEventHandler<Control, EventHandler<VisualTreeAttachmentEventArgs>>(placementTarget, TargetDetached,
|
461 | 462 | (x, handler) => x.DetachedFromVisualTree += handler,
|
462 | 463 | (x, handler) => x.DetachedFromVisualTree -= handler).DisposeWith(handlerCleanup);
|
463 |
| - |
| 464 | + |
464 | 465 | if (topLevel is Window window && window.PlatformImpl != null)
|
465 | 466 | {
|
466 | 467 | SubscribeToEventHandler<Window, EventHandler>(window, WindowDeactivated,
|
467 | 468 | (x, handler) => x.Deactivated += handler,
|
468 | 469 | (x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup);
|
469 |
| - |
| 470 | + |
470 | 471 | SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus,
|
471 | 472 | (x, handler) => x.LostFocus += handler,
|
472 | 473 | (x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
|
@@ -500,6 +501,12 @@ public void Open()
|
500 | 501 | (x, handler) => x.Closed -= handler).DisposeWith(handlerCleanup);
|
501 | 502 | }
|
502 | 503 | }
|
| 504 | + else if (topLevel is { } tl && tl.PlatformImpl is ITopLevelImpl pimpl) |
| 505 | + { |
| 506 | + SubscribeToEventHandler<ITopLevelImpl, Action>(pimpl, TopLevelLostPlatformFocus, |
| 507 | + (x, handler) => x.LostFocus += handler, |
| 508 | + (x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup); |
| 509 | + } |
503 | 510 |
|
504 | 511 | InputManager.Instance?.Process.Subscribe(ListenForNonClientClick).DisposeWith(handlerCleanup);
|
505 | 512 |
|
@@ -963,6 +970,14 @@ private void ParentClosed(object? sender, EventArgs e)
|
963 | 970 | }
|
964 | 971 | }
|
965 | 972 |
|
| 973 | + private void TopLevelLostPlatformFocus() |
| 974 | + { |
| 975 | + if (IsLightDismissEnabled) |
| 976 | + { |
| 977 | + Close(); |
| 978 | + } |
| 979 | + } |
| 980 | + |
966 | 981 | private void PlacementTargetTransformChanged(Visual v, Matrix? matrix)
|
967 | 982 | {
|
968 | 983 | if (_openState is not null)
|
|
0 commit comments