KeyBinding

Jan 15, 2010 at 5:43 PM

Haven't tried it yet, but I don't see any explicit support for binding RelayCommands to KeyBinding's or CommandBindings mentioned in MVVM Light.  Am I missing anything?

Coordinator
Jan 20, 2010 at 10:50 AM

Hi,

No you are not missing anything, this is correct.

There are some ways around the lack of KeyBinding: Use an EventToCommand to map the Window's KeyDown event to a command, and pass the EventArgs to the command using the EventToCommand.PassEventArgsToCommand property and setting it to true. I show how to do this for a SL4 drag&drop event here:

http://blog.galasoft.ch/archive/2009/12/17/silverlight-4-dragampdrop-with-eventtocommand.aspx

This works for KeyDown events too.

For CommandBinding: This is a feature I want to add in a next version. I will think if there is a work around more practical than to define your own event in the Window and calling the Command on the VM directly. Maybe I find a behavior somewhere to do that (in a temporary manner).

Thanks,

Laurent

 

Mar 2, 2010 at 2:51 AM

Hi,

How could I bind short key to my commands? For example:

<KeyBinding Command="{Binding MyCommand}" Key="F4" Modifiers="ALT" />

Coordinator
Mar 25, 2010 at 11:56 AM

Hi,

Sorry for the delay in the reply.

This is possible in WPF4, but not in WPF3.5SP1. I would recommend to upgrade if you can. WPF4 makes many things much easier, performs better and the runtime is smaller.

Cheers,

Laurent

Coordinator
Mar 25, 2010 at 11:57 AM

One more thing: If you really cannot upgrade to WPF4, check Mark Smith's library:

http://www.julmar.com/blog/mark/PermaLink,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx

He has some helpers that allow you to do what you need.

Cheers,

Laurent