I have a RoutedUICommand
called Comment Selection
. I need to add an input gesture for this command as it is in VIsual Studio, ie. (Ctrl+K, Ctrl+C).
How can I do this? Plz help me. (Keep VS functionality in mind).
Regards, Jawahar
I have a RoutedUICommand
called Comment Selection
. I need to add an input gesture for this command as it is in VIsual Studio, ie. (Ctrl+K, Ctrl+C).
How can I do this? Plz help me. (Keep VS functionality in mind).
Regards, Jawahar
This code is made for "Ctrl+W, Ctrl+E" and/or "Ctrl+W, E" combinations, however you can parametrize it for any key combinations:
XAML:
C#:
I've found this blog post which I think could be of help
http://kent-boogaart.com/blog/multikeygesture
Basically, WPF has no built in support for it, but subclassing InputGesture or KeyGesture seems like a possible way to achieve this without too much hassle.
Here's how I cobbled together something that actually works. I just wish I could credit the person or persons who paved the way to my Path of Enlightenment.
Let's say your application is called Heckler. Add a namespace tag for your application to the
Window
object:Now add a
CommandBindings
property tag and start your collection ofCommandBinding
objects. Here we add custom command Comment Selection:Add a
MenuItem
to a mainMenu
'sMenuItem
:In the
Window
code-behind, add your CustomCommands class and custom command:Now wire up your event handlers:
You should be good to go. I hope this helps and I didn't miss anything!