A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.5 KiB

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<ICommand> CommandProperty =
AvaloniaProperty.Register<KeyBinding, ICommand>("Command");
public ICommand Command
{
get { return GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public static readonly StyledProperty<object> CommandParameterProperty =
AvaloniaProperty.Register<KeyBinding, object>("CommandParameter");
public object CommandParameter
{
get { return GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}
public static readonly StyledProperty<KeyGesture> GestureProperty =
AvaloniaProperty.Register<KeyBinding, KeyGesture>("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);
}
}
}
}