Browse Source

Added `Popup.OverlayInputPassThroughElement`.

pull/4099/head
Steven Kirk 6 years ago
parent
commit
b43c8f4cef
  1. 28
      src/Avalonia.Controls/Primitives/Popup.cs

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

@ -87,6 +87,12 @@ namespace Avalonia.Controls.Primitives
public static readonly StyledProperty<bool> OverlayDismissEventPassThroughProperty = public static readonly StyledProperty<bool> OverlayDismissEventPassThroughProperty =
AvaloniaProperty.Register<Popup, bool>(nameof(OverlayDismissEventPassThrough)); AvaloniaProperty.Register<Popup, bool>(nameof(OverlayDismissEventPassThrough));
public static readonly DirectProperty<Popup, IInputElement> OverlayInputPassThroughElementProperty =
AvaloniaProperty.RegisterDirect<Popup, IInputElement>(
nameof(OverlayInputPassThroughElement),
o => o.OverlayInputPassThroughElement,
(o, v) => o.OverlayInputPassThroughElement = v);
/// <summary> /// <summary>
/// Defines the <see cref="HorizontalOffset"/> property. /// Defines the <see cref="HorizontalOffset"/> property.
/// </summary> /// </summary>
@ -125,6 +131,7 @@ namespace Avalonia.Controls.Primitives
private bool _isOpen; private bool _isOpen;
private bool _ignoreIsOpenChanged; private bool _ignoreIsOpenChanged;
private PopupOpenState? _openState; private PopupOpenState? _openState;
private IInputElement _overlayInputPassThroughElement;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="Popup"/> class. /// Initializes static members of the <see cref="Popup"/> class.
@ -286,6 +293,16 @@ namespace Avalonia.Controls.Primitives
set => SetValue(OverlayDismissEventPassThroughProperty, value); set => SetValue(OverlayDismissEventPassThroughProperty, value);
} }
/// <summary>
/// Gets or sets an element that should receive pointer input events even when underneath
/// the popup's overlay.
/// </summary>
public IInputElement OverlayInputPassThroughElement
{
get => _overlayInputPassThroughElement;
set => SetAndRaise(OverlayInputPassThroughElementProperty, ref _overlayInputPassThroughElement, value);
}
/// <summary> /// <summary>
/// Gets or sets the Horizontal offset of the popup in relation to the <see cref="PlacementTarget"/>. /// Gets or sets the Horizontal offset of the popup in relation to the <see cref="PlacementTarget"/>.
/// </summary> /// </summary>
@ -430,7 +447,14 @@ namespace Avalonia.Controls.Primitives
if (dismissLayer != null) if (dismissLayer != null)
{ {
dismissLayer.IsVisible = true; dismissLayer.IsVisible = true;
DeferCleanup(Disposable.Create(() => dismissLayer.IsVisible = false)); dismissLayer.InputPassThroughElement = _overlayInputPassThroughElement;
DeferCleanup(Disposable.Create(() =>
{
dismissLayer.IsVisible = false;
dismissLayer.InputPassThroughElement = null;
}));
DeferCleanup(SubscribeToEventHandler<LightDismissOverlayLayer, EventHandler<PointerPressedEventArgs>>( DeferCleanup(SubscribeToEventHandler<LightDismissOverlayLayer, EventHandler<PointerPressedEventArgs>>(
dismissLayer, dismissLayer,
PointerPressedDismissOverlay, PointerPressedDismissOverlay,
@ -694,7 +718,7 @@ namespace Avalonia.Controls.Primitives
private void WindowLostFocus() private void WindowLostFocus()
{ {
if(IsLightDismissEnabled) if (IsLightDismissEnabled)
Close(); Close();
} }

Loading…
Cancel
Save