WPF : Command routing for Keyboard shortcuts.

Posted by Sprotty on Stack Overflow See other posts from Stack Overflow or by Sprotty
Published on 2011-01-09T20:49:39Z Indexed on 2011/01/09 20:53 UTC
Read the original article Hit count: 253

Basically I want to create a keyboard shortcut which is valid within the scope of a window, and not just enabled when focus is within the control that binds it.

in more detail....

I have a window which has 3 controls

  • a toolbar
  • textbox
  • Custom Control

The toolbar has a button bound to the Command CustomCommands.CmdA and linked to 'Ctrl-T'.

My Custom Control can process CmdA. When I run the app and click on my custom control CmdA is enabled and works fine. Also Ctrl-T cause the command to fire.

However when I select the text box, my custom command CmdA becomes disabled.

I can rectify this by setting the command target for CmdA's button. Now when I select the textBox, CmdA is still enabled.

But the Keyboard shortcut Ctrl-T does nothing.

Is there any easy way to change the scope of keyboard shortcuts? Or do I need to catch the keypress somewhere lower down, and work out which Command it relates to and route it myself (if so is there a framework within which to do this?)

Many Thanks Simon

© Stack Overflow or respective owner

Related posts about wpf

Related posts about keyboard-shortcuts