public interface IRunicMenuCommandSource A Window's root ViewModel that runs the commands of the application's menu bar while its Window is the key window.
Remarks
The host's menu bar names commands by id, such as file.save (Runic Desktop's DesktopHostOptions.MenuBar). The host asks the root ViewModel once for each id when the Window opens, and again when the menu bar changes, in the ViewModel's model turn: public sealed partial class EditorViewModel : ObservableObject, IRunicMenuCommandSource
{
public ICommand? GetMenuCommand(string commandId) => commandId switch
{
"file.save" => SaveCommand,
"edit.find" => Find.OpenCommand, // a child ViewModel's command
_ => null,
};
} An item follows its command's ICommand.CanExecute (and stays disabled when the menu bar declares it disabled), read with the item's command parameter (DesktopMenuItem.CommandParameter, null for none) and updated on ICommand.CanExecuteChanged, and runs ICommand.Execute with the same parameter in the model turn, so one command can serve several items, such as one per recent file. An id the ViewModel returns null for falls to the application's commands (RunicDesktopHost.UseApplicationMenu), and is disabled without one.
Runic Desktop shows the menu bar natively, and a page can render the same bar with the window's MenuBarPresentation set to Page: its items run through the same commands.
Methods
GetMenuCommand
ICommand? GetMenuCommand(string commandId) Gets the command for a menu bar id, or null when this Window does not run it.
Parameters
commandIdThe menu item's command id.