0

I'm looking for a solution of adding modifiers to EventToCommand usign mvvm light. What I want to achieve is binding a command to let's say mouseEnter but only if the ctrl is pressed. Below I have just a mouseenter command.

<i:Interaction.Triggers>
  <i:EventTrigger EventName="MouseEnter">
    <cmd:EventToCommand Command="{Binding TestCmd}"/>
  </i:EventTrigger>
</i:Interaction.Triggers>

Any idea how to add keyboard modifier to it?

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
Bartek
  • 149
  • 3
  • 13

2 Answers2

1

Just do this:

TestCmd = new RelayCommand(() =>
{
    // command action here

}, () => Keyboard.Modifiers == ModifierKeys.Control);
bugged87
  • 3,026
  • 2
  • 26
  • 42
0

I think the best solution is to use the CanExecute feature of RelayCommand.

a solution could be :

TestCmd= new RelayCommand<MouseEventArgs>(e =>
{
     // do your command
},   e =>
{
     return (Keyboard.Modifiers & ModifierKeys.Control) > 0;
});
Cybermaxs
  • 24,378
  • 8
  • 83
  • 112