I am developing a wpf application using MVVM pattern. I need to separately handle Key press & release events, (e.g. in media players fwd/rev happen till user keeps key pressed & stops when he releases). After searching a lot, still I couldn't find any way to do it. Can anybody please help.
Handling Key press & release events in MVVM
3k Views Asked by Nitin At
2
There are 2 best solutions below
0

I'm guessing, You will bind the Command
to Button
. If you want the Commands to fire repeatedly, you can use RepeatButton. It was designed for that purpose.You can bind your command to Command
Property. It will fire your methods repeatedly until RepeatButton
is released.
Thanks for your suggestions. I found a way to do this by using interactivity triggers & dependency property. Following is the dependency property for Command.
Then just use it in the xaml as below:
Where the KeyReleaseCommand & KeyDownCommand are RelayCommand in your ViewModel.