|
|
@ -8,6 +8,7 @@ using Avalonia.Controls.Presenters; |
|
|
using Avalonia.Controls.Primitives.PopupPositioning; |
|
|
using Avalonia.Controls.Primitives.PopupPositioning; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input.Raw; |
|
|
using Avalonia.Input.Raw; |
|
|
|
|
|
using Avalonia.Layout; |
|
|
using Avalonia.LogicalTree; |
|
|
using Avalonia.LogicalTree; |
|
|
using Avalonia.Metadata; |
|
|
using Avalonia.Metadata; |
|
|
using Avalonia.Platform; |
|
|
using Avalonia.Platform; |
|
|
@ -395,7 +396,7 @@ namespace Avalonia.Controls.Primitives |
|
|
_isOpenRequested = false; |
|
|
_isOpenRequested = false; |
|
|
var popupHost = OverlayPopupHost.CreatePopupHost(placementTarget, DependencyResolver); |
|
|
var popupHost = OverlayPopupHost.CreatePopupHost(placementTarget, DependencyResolver); |
|
|
|
|
|
|
|
|
var handlerCleanup = new CompositeDisposable(5); |
|
|
var handlerCleanup = new CompositeDisposable(7); |
|
|
|
|
|
|
|
|
popupHost.BindConstraints(this, WidthProperty, MinWidthProperty, MaxWidthProperty, |
|
|
popupHost.BindConstraints(this, WidthProperty, MinWidthProperty, MaxWidthProperty, |
|
|
HeightProperty, MinHeightProperty, MaxHeightProperty, TopmostProperty).DisposeWith(handlerCleanup); |
|
|
HeightProperty, MinHeightProperty, MaxHeightProperty, TopmostProperty).DisposeWith(handlerCleanup); |
|
|
@ -423,14 +424,28 @@ namespace Avalonia.Controls.Primitives |
|
|
(x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup); |
|
|
(x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup); |
|
|
|
|
|
|
|
|
SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus, |
|
|
SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus, |
|
|
(x, handler) => x.LostFocus += handler, |
|
|
(x, handler) => x.LostFocus += handler, |
|
|
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup); |
|
|
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup); |
|
|
|
|
|
|
|
|
|
|
|
SubscribeToEventHandler<IWindowImpl, Action<PixelPoint>>(window.PlatformImpl, WindowPositionChanged, |
|
|
|
|
|
(x, handler) => x.PositionChanged += handler, |
|
|
|
|
|
(x, handler) => x.PositionChanged -= handler).DisposeWith(handlerCleanup); |
|
|
|
|
|
|
|
|
|
|
|
if (placementTarget is Layoutable layoutTarget) |
|
|
|
|
|
{ |
|
|
|
|
|
// If the placement target is moved, update the popup position
|
|
|
|
|
|
SubscribeToEventHandler<Layoutable, EventHandler>(layoutTarget, PlacementTargetLayoutUpdated, |
|
|
|
|
|
(x, handler) => x.LayoutUpdated += handler, |
|
|
|
|
|
(x, handler) => x.LayoutUpdated -= handler).DisposeWith(handlerCleanup); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else if (topLevel is PopupRoot parentPopupRoot) |
|
|
{ |
|
|
{ |
|
|
var parentPopupRoot = topLevel as PopupRoot; |
|
|
SubscribeToEventHandler<PopupRoot, EventHandler<PixelPointEventArgs>>(parentPopupRoot, ParentPopupPositionChanged, |
|
|
|
|
|
(x, handler) => x.PositionChanged += handler, |
|
|
|
|
|
(x, handler) => x.PositionChanged -= handler).DisposeWith(handlerCleanup); |
|
|
|
|
|
|
|
|
if (parentPopupRoot?.Parent is Popup popup) |
|
|
if (parentPopupRoot.Parent is Popup popup) |
|
|
{ |
|
|
{ |
|
|
SubscribeToEventHandler<Popup, EventHandler<EventArgs>>(popup, ParentClosed, |
|
|
SubscribeToEventHandler<Popup, EventHandler<EventArgs>>(popup, ParentClosed, |
|
|
(x, handler) => x.Closed += handler, |
|
|
(x, handler) => x.Closed += handler, |
|
|
@ -795,6 +810,12 @@ namespace Avalonia.Controls.Primitives |
|
|
Close(); |
|
|
Close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void WindowPositionChanged(PixelPoint pp) => HandlePositionChange(); |
|
|
|
|
|
|
|
|
|
|
|
private void PlacementTargetLayoutUpdated(object src, EventArgs e) => HandlePositionChange(); |
|
|
|
|
|
|
|
|
|
|
|
private void ParentPopupPositionChanged(object src, PixelPointEventArgs e) => HandlePositionChange(); |
|
|
|
|
|
|
|
|
private IgnoreIsOpenScope BeginIgnoringIsOpen() |
|
|
private IgnoreIsOpenScope BeginIgnoringIsOpen() |
|
|
{ |
|
|
{ |
|
|
return new IgnoreIsOpenScope(this); |
|
|
return new IgnoreIsOpenScope(this); |
|
|
|