Hotkeys
Various Controls that implement ICommandSource
have a HotKey
property that you can set or bind to. Pressing the hotkey will execute the command bound to the Control.
<Menu>
<MenuItem Header="_File">
<MenuItem x:Name="SaveMenuItem" Header="_Save" Command="{Binding SaveCommand}" HotKey="Ctrl+S"/>
</MenuItem>
</Menu>
You can also use the static methods of the HotKeyManager
class to set and get hotkeys from code:
InitializeComponent();
var saveMenuItem = this.FindControl<Avalonia.Controls.MenuItem>("SaveMenuItem");
HotKeyManager.SetHotKey(saveMenuItem, new KeyGesture(Key.S, KeyModifiers.Control));
See the Locating Controls section for more information on finding named Controls with the FindControl method.