Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何设置自定义命令的默认热键?_C#_Wpf_Command_Hotkeys - Fatal编程技术网

C# 如何设置自定义命令的默认热键?

C# 如何设置自定义命令的默认热键?,c#,wpf,command,hotkeys,C#,Wpf,Command,Hotkeys,我已经创建了我的自定义命令New,Edit和Delet,我在InputBinding中设置了这个热键,但是当我每次都需要使用我的命令时,这是非常困难的 Copy命令示例,我不需要设置热键,但它有默认热键Ctrl+C 如何为我的客户命令设置默认热键Ctrl+N、Ctrl+E和Ctrl+D public static class HWCommand { static RoutedUICommand save = new RoutedUICommand("Save", "Save", type

我已经创建了我的自定义命令
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>

您可以使用不同的构造函数

您可以在其中指定
InputGestureCollection
,如下所示:

static RoutedUICommand novo = new RoutedUICommand(
                                     "Novo", 
                                     "Novo", 
                                     typeof(HWCommand), 
                                     new InputGestureCollection(
                                         new InputGesture[] { new KeyGesture(Key.N, ModifierKeys.Control) }
                                     ));

非常感谢你!它正在工作!但是其他问题。。。它接受InputGestureCollection,所以我可以为该命令设置多个热键吗?从技术上讲,您可以放置整个
InputBirters
列表,其中包括和,但我没有尝试,
static RoutedUICommand novo = new RoutedUICommand(
                                     "Novo", 
                                     "Novo", 
                                     typeof(HWCommand), 
                                     new InputGestureCollection(
                                         new InputGesture[] { new KeyGesture(Key.N, ModifierKeys.Control) }
                                     ));