Key pressed in ViewModel

Topics: Prism v1, Prism v2 - Silverlight 2, Prism v2 - Silverlight 3, Prism v2 - Silverlight 4, Prism v4 - Silverlight 4
Oct 21, 2010 at 3:11 PM

Hi !

I want to catch my kedown event in ViewModel. Is there any way to track which key was pressed in the ViewModel instead of the command or behaviour written for the mentioned purpose.

Thanks in advance,

Kausar Mehmood

Oct 22, 2010 at 7:27 PM

Hi Kausar,

If you want to avoid using Commands, I think that you could use .Net Events in your Shell Window, as shown below:

<Window x:Class="HelloWorld.Shell"
... KeyDown="Window_KeyDown">

Then, you could use Event Aggregator to notify your View Model. For more information about this you could take a look at the following documentation section on MSDN:

Additionally, you could check the EventAggregation Quickstart.

Hope this helps.

Fernando Antivero