Table of Contents

Class ContextMenu

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A control context menu.

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

Constructors

ContextMenu()

Initializes a new instance of the ContextMenu class.

public ContextMenu()

ContextMenu(IMenuInteractionHandler)

Initializes a new instance of the ContextMenu class.

public ContextMenu(IMenuInteractionHandler interactionHandler)

Parameters

interactionHandler IMenuInteractionHandler

The menu interaction handler.

Fields

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>

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>

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

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

HorizontalOffset

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

public double HorizontalOffset { get; set; }

Property Value

double

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.

public Control? PlacementTarget { get; set; }

Property Value

Control

VerticalOffset

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

public double VerticalOffset { get; set; }

Property Value

double

WindowManagerAddShadowHint

public bool WindowManagerAddShadowHint { get; set; }

Property Value

bool

Methods

Close()

Closes the menu.

public override void Close()

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 menu.

public override void Open()

Open(Control?)

Opens a context menu on the specified control.

public void Open(Control? control)

Parameters

control Control

The control.

Events

Closing

Occurs when the value of the Avalonia.Controls.ContextMenu.IsOpen property is changing from true to false.

public event CancelEventHandler? Closing

Event Type

CancelEventHandler

Opening

Occurs when the value of the Avalonia.Controls.ContextMenu.IsOpen property is changing from false to true.

public event CancelEventHandler? Opening

Event Type

CancelEventHandler