How to catch key action in popup

Topics: Prism v2 - WPF 3.5
Aug 27, 2009 at 6:37 AM

Hi everybody

I would like to catch some key action in my application but unfortunatly it doesn't work. I use MVVM pattern and before Prism i use

the commandReference class of MVVM toolkit to catch Key action. Now with Prism i do some thing like that.

        <v2CM:CommandReference x:Key="saveAnimalCmd" Command="{Binding SaveAnimal}"/>
        <v2CM:CommandReference x:Key="updateAnimalCmd" Command="{Binding UpdateAnimal}"/>
        <KeyBinding Key="ENTER" Command="{StaticResource saveAnimalCmd}"/>
        <KeyBinding Key="ESC" Command="{StaticResource saveAnimalCmd}"/>
        <KeyBinding Key="Pgdn" Command="{StaticResource saveAnimalCmd}"/>
        <KeyBinding Key="F3" Command="{StaticResource updateAnimalCmd}"/>

The usercontrol is used in popup region. 

Any help will be appreciate.


Aug 27, 2009 at 9:08 PM


The following is an extract from the MSDN documentation related to KeyGestures:

"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. For example, you can create a KeyGesture by using only the F12 key, but to use the X key in a KeyGesture it must be paired with a modifier key."

Is this associated to your problem?

Please let me know if this helps.

Damian Schenkelman

Aug 27, 2009 at 11:36 PM

Hi Damian

Sorry  this is not assiciated to my problem. I've already used KeyGestures with ModifierKeys to catch Keys action.

The problem is that in prism i use UserControl.Resources instead of Window.Resources to define my CommandReference (See code above).

I think the UserControl can not get the focus as a Window. And if the UserControl can not be focused then the key action can not be launched.