Table of Contents

Class MenuBase

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Base class for menu controls.

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

Constructors

MenuBase()

Initializes a new instance of the MenuBase class.

protected MenuBase()

MenuBase(IMenuInteractionHandler)

Initializes a new instance of the MenuBase class.

protected MenuBase(IMenuInteractionHandler interactionHandler)

Parameters

interactionHandler IMenuInteractionHandler

The menu interaction handler.

Fields

ClosedEvent

Defines the Closed event.

public static readonly RoutedEvent<RoutedEventArgs> ClosedEvent

Field Value

RoutedEvent<RoutedEventArgs>

IsOpenProperty

Defines the IsOpen property.

public static readonly DirectProperty<MenuBase, bool> IsOpenProperty

Field Value

DirectProperty<MenuBase, bool>

OpenedEvent

Defines the Opened event.

public static readonly RoutedEvent<RoutedEventArgs> OpenedEvent

Field Value

RoutedEvent<RoutedEventArgs>

Properties

InteractionHandler

Gets the interaction handler for the menu.

protected IMenuInteractionHandler InteractionHandler { get; }

Property Value

IMenuInteractionHandler

IsOpen

Gets a value indicating whether the menu is open.

public bool IsOpen { get; protected set; }

Property Value

bool

Methods

Close()

Closes the menu.

public abstract void Close()

CreateContainerForItemOverride(object?, int, object?)

Creates or a container that can be used to display an item.

protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)

Parameters

item object
index int
recycleKey object

Returns

Control

NeedsContainerOverride(object?, int, out object?)

Determines whether the specified item can be its own container.

protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)

Parameters

item object

The item to check.

index int

The index of the item.

recycleKey object

When the method returns, contains a key that can be used to locate a previously recycled container of the correct type, or null if the item cannot be recycled. If the item is its own container then by definition it cannot be recycled, so recycleKey shoud be set to null.

Returns

bool

true if the item needs a container; otherwise false if the item can itself be used as a container.

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.

OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is removed from a rooted visual tree.

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnKeyDown(KeyEventArgs)

Handles directional navigation within the ItemsControl.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The key events.

OnSubmenuOpened(RoutedEventArgs)

Called when a submenu opens somewhere in the menu.

protected virtual void OnSubmenuOpened(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

Open()

Opens the menu.

public abstract void Open()

Events

Closed

Occurs when a Menu is closed.

public event EventHandler<RoutedEventArgs>? Closed

Event Type

EventHandler<RoutedEventArgs>

Opened

Occurs when a Menu is opened.

public event EventHandler<RoutedEventArgs>? Opened

Event Type

EventHandler<RoutedEventArgs>