Primary WPF APIs:
RoutedEvent, bubbling/tunneling handlersRoutedCommand, CommandBinding, InputBinding, KeyBindingPrimary Avalonia APIs:
RoutedEvent and routed event handlersICommand command sources (Button, MenuItem, etc.)KeyBinding, KeyGesture, HotKey| WPF | Avalonia |
|---|---|
RoutedCommand + CommandBinding |
ICommand on command sources + explicit handlers |
CanExecute routing |
command CanExecute + view-model state |
routed events (Preview*, *) |
routed input events with tunnel/bubble semantics |
| WPF | Avalonia |
|---|---|
<Window.InputBindings> |
root KeyBindings on Window/UserControl |
InputGestureText in menu |
InputGesture display hint on MenuItem |
| shortcut execution | HotKey or KeyBinding |
WPF XAML:
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+S" Command="{Binding SaveCommand}" />
</Window.InputBindings>
<MenuItem Header="_Save" Command="{Binding SaveCommand}" InputGestureText="Ctrl+S" />
Avalonia XAML:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:EditorViewModel">
<UserControl.KeyBindings>
<KeyBinding Gesture="Ctrl+S" Command="{CompiledBinding SaveCommand}" />
</UserControl.KeyBindings>
<Menu>
<MenuItem Header="_File">
<MenuItem Header="_Save"
Command="{CompiledBinding SaveCommand}"
InputGesture="Ctrl+S"
HotKey="Ctrl+S" />
</MenuItem>
</Menu>
</UserControl>
using Avalonia.Controls;
using Avalonia.Input;
var root = new UserControl();
root.KeyBindings.Add(new KeyBinding
{
Gesture = KeyGesture.Parse("Ctrl+S"),
Command = viewModel.SaveCommand
});
InputGesture is only hint text; wire HotKey or KeyBinding for execution.