Browse Source

dismiss popups when toplevel deactivates in embedded scenarios (#18527)

release/11.2.6
Emmanuel Hansen 11 months ago
committed by Julien Lebosquain
parent
commit
408ca45772
  1. 19
      src/Avalonia.Controls/Primitives/Popup.cs

19
src/Avalonia.Controls/Primitives/Popup.cs

@ -14,6 +14,7 @@ using Avalonia.Metadata;
using Avalonia.Platform;
using Avalonia.VisualTree;
using Avalonia.Media;
using Avalonia.Interactivity;
namespace Avalonia.Controls.Primitives
{
@ -460,13 +461,13 @@ namespace Avalonia.Controls.Primitives
SubscribeToEventHandler<Control, EventHandler<VisualTreeAttachmentEventArgs>>(placementTarget, TargetDetached,
(x, handler) => x.DetachedFromVisualTree += handler,
(x, handler) => x.DetachedFromVisualTree -= handler).DisposeWith(handlerCleanup);
if (topLevel is Window window && window.PlatformImpl != null)
{
SubscribeToEventHandler<Window, EventHandler>(window, WindowDeactivated,
(x, handler) => x.Deactivated += handler,
(x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup);
SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus,
(x, handler) => x.LostFocus += handler,
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
@ -500,6 +501,12 @@ namespace Avalonia.Controls.Primitives
(x, handler) => x.Closed -= handler).DisposeWith(handlerCleanup);
}
}
else if (topLevel is { } tl && tl.PlatformImpl is ITopLevelImpl pimpl)
{
SubscribeToEventHandler<ITopLevelImpl, Action>(pimpl, TopLevelLostPlatformFocus,
(x, handler) => x.LostFocus += handler,
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
}
InputManager.Instance?.Process.Subscribe(ListenForNonClientClick).DisposeWith(handlerCleanup);
@ -963,6 +970,14 @@ namespace Avalonia.Controls.Primitives
}
}
private void TopLevelLostPlatformFocus()
{
if (IsLightDismissEnabled)
{
Close();
}
}
private void PlacementTargetTransformChanged(Visual v, Matrix? matrix)
{
if (_openState is not null)

Loading…
Cancel
Save