Left MouseDoubleClick事件的名称是什么?

时间:2019-11-21 22:11:47

标签: c# wpf eventtrigger

我有一个EventTrigger

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

并调用MouseDoubleClick上的命令,无论是“左”还是“右”!我希望它仅在Left MouseDoubleClick上调用命令。我尝试通过将EventName更改为LeftMouseDoubleClickLeftDoubleClick来尝试,但这些都不起作用!在“属性”检查器的“事件”部分下,似乎有两个MouseDoubleClickPreviewMouseDoubleClick,但LeftMouseDoubleClick或RighMouseDoubleClick没有任何内容!

有这样的活动吗?如果是这样,名字是什么? 如果没有,该如何处理?

2 个答案:

答案 0 :(得分:2)

您可以使用InputBindings进行处理。左键双击和右键双击有特定的事件。

<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

答案 1 :(得分:1)

您可以在事件处理程序中对其进行处理。

void OnMouseDoubleClick(Object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Left)
    {
        // Left button double-click
    }
}