-1

I am trying to implement ctrl+shift+mouseover on a button in wpf, mvvm. I am doing something like:

<Button.InputBindings>
    <KeyBinding Gesture="Ctrl+Shift" Command="{Binding KeyCommand}" 
CommandParameter="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}" 
/>
</Button.InputBindings>

or something like:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
      <i:InvokeCommandAction Command="{Binding MouseOverCommand}" />
    </i:EventTrigger>
 </i:Interaction.Triggers>

I am unable to get the required behavior as Mouse Gesture does not support "MouseEnter" event. I was trying to implement in a way like:

Step 1.- Through keybinding setting a variable in the viewmodel.

Step 2.- Accessing that variable's value on MouseEnter and do whatever in the command.

Any help is appreciated.

mukul nagpal
  • 93
  • 1
  • 12
  • What do you want to achieve ? What should happen in case of Ctrl+Shift+MouseOver ? – Nawed Nabi Zada Jul 18 '18 at 06:54
  • Is MouseOver not a requirement for pressing a button? How could you press the button without mouseover? "Enter" key? What would be the difference? – Sven Bardos Jul 18 '18 at 07:14
  • Write a behavior where you check your Mouse event key modifiers. – Rekshino Jul 18 '18 at 07:28
  • I am binding a different command on Ctrl+Shift+LeftClick and a different command on Ctrl+Shift+MouseOver. Both commands are separate and used for different purposes. – mukul nagpal Jul 18 '18 at 08:07

1 Answers1

0

You could implement an attached behaviour that hooks up event handlers to the MouseEnter and MouseLeftButtonDown events and check whether the Ctrl and Shift keys are pressed by the time the events are raised, e.g.:

private void OnMouseEnter(object sender, MouseEventArgs e)
{
    if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
        && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
    {
        TheCommand.Execute(null);
    }
}
mm8
  • 163,881
  • 10
  • 57
  • 88
  • I need to implement in pure MVVM way. – mukul nagpal Jul 18 '18 at 17:10
  • That's why I suggested that you should create an attached behaviour. That is pure MVVM. So what's your point? – mm8 Jul 19 '18 at 06:49
  • If you don't know what an attached behaviour is, you should click in the link I supplied. It also sounds like you want to some more reading about MVVM...you won't solve this using input bindings and interaction triggers. – mm8 Jul 19 '18 at 07:50