WPF Keyboard Modifier on MouseBinding

I am working with the MVVM pattern in WPF (a bit new to both).

I would like to set the InputBinding to a CheckBox that matches the Control + Click event, but does not see the Modifiers property in the MouseBinding element. This is what I would like to achieve (dummy code, obviously, modifiers do not exist):

 <CheckBox> <CheckBox.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{Binding CheckboxControlClickCommand}" Modifiers="Control" /> </CheckBox.InputBindings> </CheckBox> 

Any ideas on how to do this without using events?

Thanks!

+4
source share
4 answers

I ended up using Keyboard.Modifiers in the Execute () ICommand context, which seemed to work very well.

 if (Keyboard.Modifiers != ModifierKeys.Control) return; ... 
+1
source

Use it also with keybinding!

+13
source

An old question, but it looks like MouseBinding now provides a Gesture attribute just for that.

 <CheckBox> <CheckBox.InputBindings> <MouseBinding Gesture="CTRL+LeftClick" Command="{Binding CheckboxControlClickCommand}"/> </CheckBox.InputBindings> </CheckBox> 
+1
source

I think that behavior would do the trick. You can see this link .

0
source

All Articles