【问题标题】:What's name of Left MouseDoubleClick Event?Left MouseDoubleClick 事件的名称是什么?
【发布时间】:2019-11-21 22:11:47
【问题描述】:

我有一个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 什么都没有!

有这样的活动吗?如果有,叫什么名字? 如果没有,这种情况如何处理?

【问题讨论】:

    标签: c# wpf eventtrigger


    【解决方案1】:

    您可以使用 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

    【讨论】:

    • this 的情况下,在我的ListView 中,我使用了InputBindings,但它不起作用,我不知道为什么!这就是我使用交互触发器而不是 InputBindings 的原因
    【解决方案2】:

    您可以在事件处理程序中处理它。

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

    【讨论】:

    • 但它是一个ICommand,只接受一个参数object o!我的ICommand 中可以有MouseButtonEventArgs e 吗?
    • 是的,您可以使用MultiBinding 发送多个参数。看看这个:stackoverflow.com/a/17504958/302248
    • MultiBinding 列表中的ElementNamePath 发送到MouseButtonEventArgsIMultiValueConverter 会是什么?
    猜你喜欢
    • 2011-12-19
    • 1970-01-01
    • 2011-03-25
    • 2010-09-19
    • 2011-08-15
    • 2011-02-19
    • 2017-03-09
    • 2015-10-26
    • 2019-04-24
    相关资源
    最近更新 更多