不允许双击文本框的鼠标操作

Double click mouse action of TextBox is not allowed

我正在尝试这样设置文本框的双击手势:

<TextBox>
    <TextBox.InputBindings>
        <MouseBinding Gesture="MouseDoubleClick" Command="{Binding DobleClickCommand}"/>
    </TextBox.InputBindings>
</Textbox>

但是我收到错误消息,不允许鼠标操作 MOUSEDOUBLECLICK。

我想将它绑定到我的视图模型中的命令。

是输入绑定的方式吗?

你的鼠标绑定错误,没有MouseDoubleClick,使用LeftDoubleClick。有关有效鼠标操作的列表,请查看 documentation。如果您也想执行 MiddleDoubleClickRightDoubleClick 的操作,您可以为它们创建单独的鼠标绑定到同一命令。

<MouseBinding Gesture="LeftDoubleClick" Command="{Binding TestingCommand}"/>

或者,您可以使用 MouseAction 代替 Gesture:

<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DobleClickCommand}"/>

documentation推荐使用Gesture代替MouseAction:

When defining a MouseBinding in Extensible Application Markup Language (XAML), there are two ways to specify the MouseGesture. The first way to establish a MouseBinding in XAML is to define the Gesture attribute of the MouseBinding element, which enables a syntax to specify mouse actions and modifiers as a single string; for example, "CTRL+LeftClick". The second way is to define the MouseAction attribute of the MouseBinding element.

In general, it is recommended that you use only the Gesture attribute from XAML, even if you do not specify modifiers; this avoids ambiguity, provides the most streamlined syntax, and provides the most straightforward representation for serialization.

关于difference between a MouseActionGesture:

A MouseGesture is a MouseAction with or without a set of ModifierKeys. Unlike a KeyGesture, a MouseGesture does not need to have a modifier key associated with it.