public interface IDesktopMenuWindowHost : IDesktopWindowHost, IAsyncDisposable An optional native host that shows the menu bar and context menus.
Remarks
Runic Desktop finds it by type and calls IDesktopMenuWindowHost.SetMenuBarAsync once the window has opened and again after every DesktopHost.SetMenuBar, whatever DesktopWindowHostOptions.MenuBarPresentation says: the host shows the bar only for DesktopMenuBarPresentation.Native, but matches the items' shortcuts for every presentation, after the page has seen the key and left it alone. Report DesktopWindowCapabilities.MenuBar and DesktopWindowCapabilities.ContextMenu in IDesktopWindowHost.Capabilities for what the host provides, and in IDesktopWindowHostFactory.Capabilities so validation knows it before a window opens.
Run a chosen item or matched shortcut through IDesktopMenuWindowHost.MenuCommands: ask IDesktopMenuCommandTarget.CanExecute and call IDesktopMenuCommandTarget.Execute on the window's UI thread, and show an item enabled while its declaration and CanExecute allow it. The shared rules are the macOS bar's: DesktopMenuItem.IsChecked and DesktopMenuItem.RadioGroup as declared, a disabled menu disables its entries, and the standard shortcuts of the platform stay the platform's.
Properties
MenuBarPlacement
DesktopMenuBarPlacement MenuBarPlacement { get; } Gets where the window shows its menu bar now; DesktopMenuBarPlacement.None before it opens and after it closes.
Remarks
Called from any thread; keep it cheap.
MenuCommands
IDesktopMenuCommandTarget? MenuCommands { get; set; } Gets or sets the commands of the window's menu items: Runic Desktop sets a target that asks the window's DesktopWindow.MenuCommands and then DesktopHost.MenuCommands, and logs a target that throws (event 3014). null until Runic Desktop sets it.
Methods
SetMenuBarAsync
ValueTask SetMenuBarAsync(IReadOnlyList<DesktopMenu> menus, CancellationToken cancellationToken = default) Replaces the window's menus with menus, checked by DesktopHost; empty removes them.
Parameters
menusThe menus of
DesktopHost.MenuBar, in declaration order.cancellationTokenCancels the queued native work.
Returns
A task that completes when the window shows the menus.
ShowContextMenuAsync
ValueTask<DesktopMenuItem?> ShowContextMenuAsync(ImmutableArray<DesktopMenuEntry> items, DesktopContextMenuOptions options, CancellationToken cancellationToken = default) Shows a context menu and completes with the chosen item, or null when it was dismissed.
Parameters
itemsThe entries, already checked against the context-menu rules.
optionsWhere the menu opens:
DesktopContextMenuOptions.XandDesktopContextMenuOptions.Yin CSS pixels of the page's viewport, or at the pointer.cancellationTokenCloses the menu; the task then completes as cancelled.
Returns
The chosen item, one of items, or null.
Remarks
Runic Desktop calls it only when IDesktopWindowHost.Capabilities includes DesktopWindowCapabilities.ContextMenu. A new context menu of the window dismisses the open one, which completes with null, as does a menu open while the window closes.
Events
MenuBarPlacementChanged
event EventHandler? MenuBarPlacementChanged Occurs after IDesktopMenuWindowHost.MenuBarPlacement has changed, for example when a global menu bar appeared or went away. It may be raised on the window's owning thread.