Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Application menu item and shortcut keys
posted

I have button in my application menu called New.

How do I associate Ctrl+N with it?

I would like to display next to the button text and when the user types Ctrl+N the button click event to be executed.

 

Thanks very much.

Parents
No Data
Reply
  • 54937
    Offline posted

    This is basically the same kind of thing you would have to do with a WPF menu. Normally when you want a keyboard shortcut for a command you either define an KeyBinding in the WIndow's InputBindings for that command and shortcut or for routedcommands where the shortcut is universal you would add a KeyGesture to the RoutedCommand's InputGestures. In either case you need to make sure that you have a command binding setup to handle the execute/canexecute of the command at the root level (e.g. window). Now if the command is a RoutedCommand and it has a KeyBinding in its InputGestures then the menu item will automatically show the first keybinding's gesture. If that is not the case then you have to provide the InputGestureText. In the case of wpf menuitems you would just set the InputGestureText directly however in the case of the ribbon since you are not dealing with menu items you need to set the attached MenuToolBase.InputGestureText on the ButtonTool in the menu.

Children
No Data