N.D
N.D

Reputation: 1049

KeyGesture doesn't support only one key

I want to create my custom command and to hook it up to some key. I am using KeyGesture in code behing for that purpose , and in the constructor I see that I can pass only one key (without modifierKey) but at runtime I get exception , saying :

"'None + Q' key and modifier combination is not supported for KeyGesture"

I just don't understand why there is a constructor for only one key and still I need to set also the modifier key combination in order not to get the exception.

Upvotes: 4

Views: 3603

Answers (1)

dowhilefor
dowhilefor

Reputation: 11051

Pasted from the MSDN:

In most cases, a KeyGesture must be associated with one or more ModifierKeys. The exceptions to this rule are the function keys and the numeric keypad keys, which can be a valid KeyGesture by themselves.

The problem with "normal" keys is to distinguish an actual button press from a shortcut. For example if you have a textbox, you can't use a command with the gesture Q to do something differently than inserting the character Q. If you want something like that use the KeyDown/Up commands and your own command invocation.

Upvotes: 2

Related Questions