Freddy
Freddy

Reputation: 359

How to execute a command and change focus after a keypress in a WPF app

I have a WPF app that uses MVVM Light and I wish to both execute a command on the view model and change the keyboard focus to a specific control when the user presses ALT+SHIFT+C.

Is it possible to achieve this in an elegant way?

Upvotes: 0

Views: 822

Answers (1)

metalcam
metalcam

Reputation: 402

It depends on how the shortcut key is created (if it's like Visual Studio or more like Windows - it means if you have to hold only ALT or all the keys).

But whatever the logic, You will have to first bind an Event to a Command (it might be the event keydown of one of your controls). In MVVM Light, you will have to use Interaction.Triggers with EventToCommand (there's a lot ot explanations on google and SO)

The logic would be put here in you command. Then a dependecy property as show here could be implemented for getting the focus.

Upvotes: 1

Related Questions