Skip to content

Menus markup reference

Menu, MenuBar, MenuItem, and ContextMenu.

Receiver: Menu.

Method Sets Summary
Add(MenuEntry entry) Adds an entry to the menu.
Item(Command command) Adds a semantic command item using the command’s normalized text and default access key.
Item(string text, Command command) Adds a semantic command item with a presentation and access-key override. A single underscore marks the following character as the access key; use a double underscore for a literal underscore.
Item(string text, Command command, object data) Adds a command item that passes data as the invocation argument, so several items can share one command and differ only in the value they pass.
Item(string text, bool isEnabled = true) Adds a non-executable presentation item.
ItemHeight(double value) ItemHeight Sets the per-menu item height override in DIPs; NaN (the default) uses the presenter’s default.
ItemPadding(Thickness? value) ItemPadding Sets the per-menu item padding override; null uses the presenter’s default.
Separator() Adds a separator.
SubMenu(string text, Menu subMenu, bool isEnabled = true) Adds a submenu item.

Receiver: MenuItem.

Method Sets Summary
BindCommand(ObservableValue<Command> source) bind Command Binds the semantic command invoked by this item.
BindIcon(ObservableValue<IconTemplate> source) bind Icon Binds this placement’s icon override to an observable source.
BindIsChecked(ObservableValue<TSource> source, Func<TSource, bool> convert) bind IsChecked Binds whether the check is shown to a converted observable value, such as whether a chosen value equals the one this item stands for.
BindIsChecked(ObservableValue<bool> source) bind IsChecked Binds whether the check is shown to an observable value. Clicking the item does not write it back.
BindIsEnabled(ObservableValue<bool> source) bind IsEnabled Binds the local enabled value. Command CanExecute is combined with this value and does not replace the binding.
BindText(ObservableValue<string> source) bind Text Binds this placement’s access-key-aware text override to an observable source.
Command(Command value) Command Sets the semantic command this item invokes.
CommandData(object value) CommandData Sets CommandData. The value this placement hands its command as the invocation argument, so several items can share one command and differ only in what they pass. Null lets the argument the menu captured when it opened (the item it opened over) stand in.
Icon(IconTemplate value) Icon Sets this placement’s icon override.
IsCheckable(bool value = true) IsCheckable Sets IsCheckable. Whether the item has a check slot. The slot is the icon column, which a menu with such an item keeps whether or not any check is currently shown; the item’s own icon is not shown.
IsChecked(bool value = true) IsChecked Sets IsChecked. Whether the check is shown in the slot of an item that IsCheckable. Clicking the item does not change it: the application sets it, usually from the state its command changes.
IsEnabled(bool value = true) IsEnabled Sets the local enabled state, which the command’s CanExecute is combined with rather than replacing.
OnCanClick(Func<bool> predicate) event CanClick Sets the predicate asked whether the row can be clicked. Asked again each time the menu opens.
SubMenu(Menu menu) SubMenu Sets the submenu the item opens. To detach a submenu, set SubMenu to null.
Text(string text) Text Sets the menu item’s presentation and access-key override. A single underscore marks the following character as the access key; use a double underscore for a literal underscore.

Receiver: ContextMenu.

Method Sets Summary
Add(MenuEntry entry) Adds an entry built beforehand, such as a checkable MenuItem, after the existing items.
Item(Command command) Adds a semantic command item using command presentation metadata.
Item(string text, Command command) Adds a semantic command item.
Item(string text, Command command, object data) Adds a command item that passes data as the invocation argument, so several items can share one command and differ only in the value they pass.
Item(string text, bool isEnabled = true) Adds a non-executable presentation item.
ItemHeight(double value) ItemHeight Sets the height of menu items.
ItemPadding(Thickness value) ItemPadding Sets the padding around menu items.
Items(params MenuEntry[] items) Items Replaces the menu items.
MaxMenuHeight(double value) MaxMenuHeight Sets an upper bound on the menu height; the default is no bound.
Placement(MenuPlacement value) Placement Sets where the menu opens relative to its placement target.
PlacementOffset(Point value) PlacementOffset Sets a DIP offset applied to the placement, mirrored on the flipped side.
Separator() Adds a separator.
SubMenu(string text, ContextMenu subMenu, bool isEnabled = true) Adds a submenu.
SystemBackdrop(SystemBackdrop value) SystemBackdrop Sets the material behind the menu; submenus opened from it follow. A menu in its own window gets the platform’s material, and a menu drawn inside its owner’s surface the same look from what that surface holds. Where neither can be shown, BackdropFallbackBrush is drawn under the background.

Receiver: MenuBar.

Method Sets Summary
DrawBottomSeparator(bool value = true) DrawBottomSeparator Sets a value indicating whether to draw a bottom separator line below the menu bar.
Item(Command command) Adds a command item using the command’s normalized text and default access key.
Item(MenuItem item) Adds a menu item.
Item(string text, Command command) Adds a command item with a presentation and access-key override. A single underscore marks the following character as the access key; use a double underscore for a literal underscore.
Item(string text, Menu menu) Adds a menu item with text and submenu.
Items(params MenuItem[] items) Items Sets the menu items.
Spacing(double value) Spacing Sets the spacing between menu items.