If you are developing using any sort of V-VM-M pattern, you are already loving the awesome binding powers of Wpf.
And you should also be loving ICommand and binding buttons to ICommand properties on your VM.
What you might have discovered is that binding ICommands to Keys and other input gestures is not as easy as it was with vanilla Routed Commands.
But have no fear! There is a solution.
By utilizing Josh Smith’s Element Spy trick and creating a custom InputBinding, we can gain the functionality of binding an ICommand to a Key, etc.
Here is my custom input binding :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Then when you combine the use of the ElementSpy, your xaml looks like:
1 2 3 4 5 6 7 8 |
|
Naturally the custom input binding is very simple and does not expose the Command Parameter nor the Command Target, etc. But the basic pattern is there so feel free to utilize and extend.
Happy coding!