Domanda

I had create my custom command New, Edit and Delet, I'm set this hotkeys in InputBinding, but it is very hard-working when I need use my command every time

Copy command example, I don't need set hotkey, but it has default hotkey Ctrl+C

How do can I set default hotkey Ctrl+N, Ctrl+E and Ctrl+D for my customer commands?

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; } }
}

my CommandBinding

<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>
È stato utile?

Soluzione

You can to use different constructor for your RoutedUICommand

RoutedUICommand(String, String, Type, InputGestureCollection)

where you can specify InputGestureCollection like so:

static RoutedUICommand novo = new RoutedUICommand(
                                     "Novo", 
                                     "Novo", 
                                     typeof(HWCommand), 
                                     new InputGestureCollection(
                                         new InputGesture[] { new KeyGesture(Key.N, ModifierKeys.Control) }
                                     ));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top