I need a simple way to set a shortcut for menu items.
But this don´t work with shortcut, just with click:
<MenuItem Header="Editar">
<MenuItem Header="Procurar" Name="MenuProcurar"
InputGestureText="Ctrl+F"
Click="MenuProcurar_Click">
<MenuItem.ToolTip>
<ToolTip>
Procurar
</ToolTip>
</MenuItem.ToolTip>
</MenuItem>
</MenuItem>
I am using WPF 4.0
You need to use
KeyBindings(andCommandBindingsif you (re)useRoutedCommandssuch as those found in theApplicationCommandsclass) for that in the controls where the shortcuts should work.e.g.
For custom
RoutedCommands:usage:
(It is often more convenient to implement the
ICommandinterface rather than usingRoutedCommands. You can have a constructor which takes delegates forExecuteandCanExecuteto easily create commands which do different things, such implementations are often calledDelegateCommandorRelayCommand. This way you do not needCommandBindings.)