如何为自定义命令设置默认热键
本文关键字:默认 设置 命令 自定义 | 更新日期: 2023-09-27 18:32:11
我已经创建了我的自定义命令New
,Edit
和Delet
,我在InputBinding
中设置了这个热键,但是当我每次都需要使用我的命令时,它非常努力
Copy
命令示例中,我不需要设置热键,但它具有默认的热键Ctrl + C
如何为客户命令设置默认热键 Ctrl+N、Ctrl+E 和 Ctrl+D?
public static class HWCommand
{
static RoutedUICommand save = new RoutedUICommand("Save", "Save", typeof(HWCommand));
static RoutedUICommand novo = new RoutedUICommand("Novo", "Novo", typeof(HWCommand));
static RoutedUICommand deletar = new RoutedUICommand("Deletar", "Deletar", typeof(HWCommand));
static RoutedUICommand editar = new RoutedUICommand("Editar", "Editar", typeof(HWCommand));
public static RoutedUICommand Save { get { return save; } }
public static RoutedUICommand Novo { get { return novo; } }
public static RoutedUICommand Deletar { get { return deletar; } }
public static RoutedUICommand Editar { get { return editar; } }
}
我的命令绑定
<Window.CommandBindings>
<CommandBinding Command="{x:Static hw:HWCommand.Novo}" Executed="NovoCommand_Executed"/>
<CommandBinding Command="{x:Static hw:HWCommand.Editar}" Executed="EditarCommand_Executed" CanExecute="EditCommand_CanExecuted"/>
<CommandBinding Command="{x:Static hw:HWCommand.Deletar}" Executed="DeletarCommand_Executed" CanExecute="DeletarCommand_CanExecuted"/>
</Window.CommandBindings>
你可以为你RoutedUICommand
使用不同的构造函数
RoutedUICommand(String, String, Type, InputGestureCollection)
您可以在其中指定如下所示InputGestureCollection
:
static RoutedUICommand novo = new RoutedUICommand(
"Novo",
"Novo",
typeof(HWCommand),
new InputGestureCollection(
new InputGesture[] { new KeyGesture(Key.N, ModifierKeys.Control) }
));