0

I've an EventTrigger:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseDoubleClick">
        <i:InvokeCommandAction Command="{Binding Modify}" 
                            CommandParameter="{Binding SelectedItem, ElementName=lv}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

and it invokes the command on MouseDoubleClick, doesn't matter whether it's Left or Right! I want it to Invoke the command only on Left MouseDoubleClick. I've tried by chaning the EventName as LeftMouseDoubleClick and LeftDoubleClick but those don't work! Under the Event Section of Properties Inspector It looks like there're two MouseDoubleClick and PreviewMouseDoubleClick BUT nothing for LeftMouseDoubleClick or RighMouseDoubleClick!

Is there any such Event? If so, what's the name? If there's none, how such case is handled?

2 Answers2

1

You can use InputBindings to handle this. There are specific events for left double click and right double click.

<Window.InputBindings>
    <MouseBinding MouseAction="LeftDoubleClick"
                  Command="{Binding MessageCommand}"
                  CommandParameter="Left Double Click"/>
    <MouseBinding MouseAction="MiddleDoubleClick"
                  Command="{Binding MessageCommand}"
                  CommandParameter="Middle Double Click"/>
    <MouseBinding MouseAction="RightDoubleClick"
                  Command="{Binding MessageCommand}"
                  CommandParameter="Right Double Click"/>
    <MouseBinding MouseAction="WheelClick"
                  Command="{Binding MessageCommand}"
                  CommandParameter="Wheel Click"/>
</Window.InputBindings>

This is discussed in detail in this article

  • In [this](https://stackoverflow.com/questions/58369250/listview-isnt-working-properly-with-observablecollection) case, in my `ListView` I used that `InputBindings` but it doesn't work, I don't know why! And that's the reason I've used Interaction Trigger instead of InputBindings –  Nov 21 '19 at 22:54
0

You can handle it in the event handler.

void OnMouseDoubleClick(Object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Left)
    {
        // Left button double-click
    }
}
Sach
  • 10,091
  • 8
  • 47
  • 84
  • But it's an `ICommand` that only takes one argument `object o`! Can I have `MouseButtonEventArgs e` in my `ICommand`? –  Nov 21 '19 at 22:37
  • 1
    Yes you can use `MultiBinding` to send more than one parameter. Check this out: https://stackoverflow.com/a/17504958/302248 – Sach Nov 21 '19 at 22:40
  • What would be `ElementName` and `Path` in `MultiBinding` list to send `MouseButtonEventArgs` to the `IMultiValueConverter` ? –  Nov 21 '19 at 23:48