using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace Avalonia.Input { public class KeyBinding : AvaloniaObject { public static readonly StyledProperty CommandProperty = AvaloniaProperty.Register(nameof(Command)); public ICommand Command { get { return GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } } public static readonly StyledProperty CommandParameterProperty = AvaloniaProperty.Register(nameof(CommandParameter)); public object CommandParameter { get { return GetValue(CommandParameterProperty); } set { SetValue(CommandParameterProperty, value); } } public static readonly StyledProperty GestureProperty = AvaloniaProperty.Register(nameof(Gesture)); public KeyGesture Gesture { get { return GetValue(GestureProperty); } set { SetValue(GestureProperty, value); } } public void TryHandle(KeyEventArgs args) { if (Gesture?.Matches(args) == true) { args.Handled = true; if (Command?.CanExecute(CommandParameter) == true) Command.Execute(CommandParameter); } } } }