Table of Contents

Class Popup

Namespace
Avalonia.Controls.Primitives
Assembly
Avalonia.Controls.dll

Displays a popup window.

public class Popup : Control, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IPopupHostProvider
Inheritance
Popup
Implements
Inherited Members
Extension Methods

Constructors

Popup()

public Popup()

Fields

ChildProperty

Defines the Child property.

public static readonly StyledProperty<Control?> ChildProperty

Field Value

StyledProperty<Control>

CustomPopupPlacementCallbackProperty

Defines the CustomPopupPlacementCallback property.

public static readonly StyledProperty<CustomPopupPlacementCallback?> CustomPopupPlacementCallbackProperty

Field Value

StyledProperty<CustomPopupPlacementCallback>

HorizontalOffsetProperty

Defines the HorizontalOffset property.

public static readonly StyledProperty<double> HorizontalOffsetProperty

Field Value

StyledProperty<double>

InheritsTransformProperty

Defines the InheritsTransform property.

public static readonly StyledProperty<bool> InheritsTransformProperty

Field Value

StyledProperty<bool>

IsLightDismissEnabledProperty

Defines the IsLightDismissEnabled property.

public static readonly StyledProperty<bool> IsLightDismissEnabledProperty

Field Value

StyledProperty<bool>

IsOpenProperty

Defines the IsOpen property.

public static readonly StyledProperty<bool> IsOpenProperty

Field Value

StyledProperty<bool>

IsUsingOverlayLayerProperty

Defines the IsUsingOverlayLayer property.

public static readonly DirectProperty<Popup, bool> IsUsingOverlayLayerProperty

Field Value

DirectProperty<Popup, bool>

OverlayDismissEventPassThroughProperty

Defines the OverlayDismissEventPassThrough property.

public static readonly StyledProperty<bool> OverlayDismissEventPassThroughProperty

Field Value

StyledProperty<bool>

OverlayInputPassThroughElementProperty

Defines the OverlayInputPassThroughElement property.

public static readonly StyledProperty<IInputElement?> OverlayInputPassThroughElementProperty

Field Value

StyledProperty<IInputElement>

PlacementAnchorProperty

Defines the PlacementAnchor property.

public static readonly StyledProperty<PopupAnchor> PlacementAnchorProperty

Field Value

StyledProperty<PopupAnchor>

PlacementConstraintAdjustmentProperty

Defines the PlacementConstraintAdjustment property.

public static readonly StyledProperty<PopupPositionerConstraintAdjustment> PlacementConstraintAdjustmentProperty

Field Value

StyledProperty<PopupPositionerConstraintAdjustment>

PlacementGravityProperty

Defines the PlacementGravity property.

public static readonly StyledProperty<PopupGravity> PlacementGravityProperty

Field Value

StyledProperty<PopupGravity>

PlacementProperty

Defines the Placement property.

public static readonly StyledProperty<PlacementMode> PlacementProperty

Field Value

StyledProperty<PlacementMode>

PlacementRectProperty

Defines the PlacementRect property.

public static readonly StyledProperty<Rect?> PlacementRectProperty

Field Value

StyledProperty<Rect?>

PlacementTargetProperty

Defines the PlacementTarget property.

public static readonly StyledProperty<Control?> PlacementTargetProperty

Field Value

StyledProperty<Control>

ShouldUseOverlayLayerProperty

Defines the ShouldUseOverlayLayer property.

public static readonly StyledProperty<bool> ShouldUseOverlayLayerProperty

Field Value

StyledProperty<bool>

TakesFocusFromNativeControlProperty

Defines the TakesFocusFromNativeControl property.

public static readonly AttachedProperty<bool> TakesFocusFromNativeControlProperty

Field Value

AttachedProperty<bool>

TopmostProperty

Defines the Topmost property.

public static readonly StyledProperty<bool> TopmostProperty

Field Value

StyledProperty<bool>

VerticalOffsetProperty

Defines the VerticalOffset property.

public static readonly StyledProperty<double> VerticalOffsetProperty

Field Value

StyledProperty<double>

WindowManagerAddShadowHintProperty

Defines the WindowManagerAddShadowHint property.

public static readonly StyledProperty<bool> WindowManagerAddShadowHintProperty

Field Value

StyledProperty<bool>

Properties

Child

Gets or sets the control to display in the popup.

[Content]
public Control? Child { get; set; }

Property Value

Control

CustomPopupPlacementCallback

Gets or sets a delegate handler method that positions the Popup control, when Placement is set to Custom.

public CustomPopupPlacementCallback? CustomPopupPlacementCallback { get; set; }

Property Value

CustomPopupPlacementCallback

DependencyResolver

Gets or sets a dependency resolver for the PopupRoot.

public IAvaloniaDependencyResolver? DependencyResolver { get; set; }

Property Value

IAvaloniaDependencyResolver

Remarks

This property allows a client to customize the behaviour of the popup by injecting a specialized dependency resolver into the PopupRoot's constructor.

HorizontalOffset

Gets or sets the Horizontal offset of the popup in relation to the PlacementTarget.

public double HorizontalOffset { get; set; }

Property Value

double

Host

public IPopupHost? Host { get; }

Property Value

IPopupHost

InheritsTransform

Gets or sets a value that determines whether the popup inherits the render transform from its PlacementTarget. Defaults to false.

public bool InheritsTransform { get; set; }

Property Value

bool

IsLightDismissEnabled

Gets or sets a value that determines how the Popup can be dismissed.

public bool IsLightDismissEnabled { get; set; }

Property Value

bool

Remarks

Light dismiss is when the user taps on any area other than the popup.

IsOpen

Gets or sets a value indicating whether the popup is currently open.

public bool IsOpen { get; set; }

Property Value

bool

IsPointerOverPopup

public bool IsPointerOverPopup { get; }

Property Value

bool

IsUsingOverlayLayer

Gets a value that indicates whether the popup is shown in the overlay layer of the parent window.

public bool IsUsingOverlayLayer { get; }

Property Value

bool

OverlayDismissEventPassThrough

Gets or sets a value indicating whether the event that closes the popup is passed through to the parent window.

public bool OverlayDismissEventPassThrough { get; set; }

Property Value

bool

Remarks

When IsLightDismissEnabled is set to true, clicks outside the popup cause the popup to close. When OverlayDismissEventPassThrough is set to false, these clicks will be handled by the popup and not be registered by the parent window. When set to true, the events will be passed through to the parent window.

OverlayInputPassThroughElement

Gets or sets an element that should receive pointer input events even when underneath the popup's overlay.

public IInputElement? OverlayInputPassThroughElement { get; set; }

Property Value

IInputElement

Placement

Gets or sets the desired placement of the popup in relation to the PlacementTarget.

public PlacementMode Placement { get; set; }

Property Value

PlacementMode

PlacementAnchor

Gets or sets the anchor point on the PlacementRect when Placement is AnchorAndGravity.

public PopupAnchor PlacementAnchor { get; set; }

Property Value

PopupAnchor

PlacementConstraintAdjustment

Gets or sets a value describing how the popup position will be adjusted if the unadjusted position would result in the popup being partly constrained.

public PopupPositionerConstraintAdjustment PlacementConstraintAdjustment { get; set; }

Property Value

PopupPositionerConstraintAdjustment

PlacementGravity

Gets or sets a value which defines in what direction the popup should open when Placement is AnchorAndGravity.

public PopupGravity PlacementGravity { get; set; }

Property Value

PopupGravity

PlacementRect

Gets or sets the anchor rectangle within the parent that the popup will be placed relative to when Placement is AnchorAndGravity.

public Rect? PlacementRect { get; set; }

Property Value

Rect?

Remarks

The placement rect defines a rectangle relative to PlacementTarget around which the popup will be opened, with PlacementAnchor determining which edge of the placement target is used.

If unset, the anchor rectangle will be the bounds of the PlacementTarget.

PlacementTarget

Gets or sets the control that is used to determine the popup's position.

[ResolveByName]
public Control? PlacementTarget { get; set; }

Property Value

Control

ShouldUseOverlayLayer

Gets or sets a value that indicates whether the popup should be shown in the overlay layer of the parent window.

public bool ShouldUseOverlayLayer { get; set; }

Property Value

bool

Remarks

When ShouldUseOverlayLayer is "false" implementation depends on the platform. Use IsUsingOverlayLayer to get actual popup behavior. This is an equvalent of OverlayPopups property of the platform options, but settable independently per each popup.

TakesFocusFromNativeControl

Gets or sets a value indicating whether the popup, on show, transfers focus from any focused native control to Avalonia. The default is true.

public bool TakesFocusFromNativeControl { get; set; }

Property Value

bool

Remarks

This property only applies to advanced native control embedding scenarios. By default, if a popup is shown when a native control is focused, focus is transferred back to Avalonia in order for the popup to receive input. If this property is set to false, then the shown popup will not receive input until it receives an interaction which explicitly focuses the popup, such as a mouse click.

Topmost

Gets or sets whether this popup appears on top of all other windows

public bool Topmost { get; set; }

Property Value

bool

VerticalOffset

Gets or sets the Vertical offset of the popup in relation to the PlacementTarget.

public double VerticalOffset { get; set; }

Property Value

double

WindowManagerAddShadowHint

Gets or sets a hint to the window manager that a shadow should be added to the popup.

public bool WindowManagerAddShadowHint { get; set; }

Property Value

bool

Methods

Close()

Closes the popup.

public void Close()

GetTakesFocusFromNativeControl(Control)

Gets the value of the TakesFocusFromNativeControl attached property on the specified control.

public static bool GetTakesFocusFromNativeControl(Control control)

Parameters

control Control

The control.

Returns

bool

IsInsidePopup(Visual)

public bool IsInsidePopup(Visual visual)

Parameters

visual Visual

Returns

bool

MeasureCore(Size)

Measures the control.

protected override Size MeasureCore(Size availableSize)

Parameters

availableSize Size

The available size for the control.

Returns

Size

A size of 0,0 as Popup itself takes up no space.

OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is added to a rooted visual tree.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is removed from a rooted logical tree.

protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

Open()

Opens the popup.

public void Open()

SetTakesFocusFromNativeControl(Control, bool)

Sets the value of the TakesFocusFromNativeControl attached property on the specified control.

public static void SetTakesFocusFromNativeControl(Control control, bool value)

Parameters

control Control

The control.

value bool

The value of the TakesFocusFromNativeControl property.

Events

Closed

Raised when the popup closes.

public event EventHandler<EventArgs>? Closed

Event Type

EventHandler<EventArgs>

Opened

Raised when the popup opens.

public event EventHandler? Opened

Event Type

EventHandler