Control.MouseDoubleClick 事件

定义

在双击或多次单击鼠标按钮时发生。Occurs when a mouse button is clicked two or more times.

public:
 event System::Windows::Input::MouseButtonEventHandler ^ MouseDoubleClick;
public event System.Windows.Input.MouseButtonEventHandler MouseDoubleClick;
member this.MouseDoubleClick : System.Windows.Input.MouseButtonEventHandler 
Public Custom Event MouseDoubleClick As MouseButtonEventHandler 

事件类型

MouseButtonEventHandler

示例

下面的示例演示如何将事件处理程序附加到 MouseDoubleClick 事件。The following example shows how to attach an event handler to the MouseDoubleClick event.

<Button Name="btn" Background="Red" 
        MouseDoubleClick="ChangeBackground">
  Background
</Button>

下面的示例演示事件的事件处理程序 MouseDoubleClickThe following example shows the event handler of the MouseDoubleClick event.

void ChangeBackground(object sender, RoutedEventArgs e)
{
    if (btn.Background == Brushes.Red)
    {
        btn.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
        btn.Content = "Control background changes from red to a blue gradient.";
    }
    else
    {
        btn.Background = Brushes.Red;
        btn.Content = "Background";
    }
}
Private Sub ChangeBackground(ByVal Sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)

    If (btn.Background Is Brushes.Red) Then

        btn.Background = New LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90)
        btn.Content = "Control background changes from red to a blue gradient."

    Else
        btn.Background = Brushes.Red
        btn.Content = "Background"
    End If

End Sub

注解

尽管此路由事件似乎是通过元素树执行冒泡路由,但实际上它是一个直接路由事件,每个事件都由元素树逐个引发 UIElementAlthough this routed event seems to follow a bubbling route through an element tree, it actually is a direct routed event that is raised along the element tree by each UIElement. 如果 Handled true 在事件处理程序中将属性设置为,则将在 MouseDoubleClick MouseDoubleClick 设置为的情况下发生沿路由的后续事件 Handled falseIf you set the Handled property to true in a MouseDoubleClick event handler, subsequent MouseDoubleClick events along the route will occur with Handled set to false. 这是控件使用者的高级事件,当用户双击控件并处理应用程序中的事件时,这些用户希望获得通知。This is a higher-level event for control consumers who want to be notified when the user double-clicks the control and to handle the event in an application.

MouseLeftButtonDown当等于2时,要处理鼠标双击的控件作者应使用该事件 ClickCountControl authors who want to handle mouse double clicks should use the MouseLeftButtonDown event when ClickCount is equal to two. 这将导致的状态 Handled 在元素树中的另一个元素处理事件时适当地传播。This will cause the state of Handled to propagate appropriately in the case where another element in the element tree handles the event.

Control类定义 PreviewMouseDoubleClickMouseDoubleClick 事件,而不是对应的单击事件。The Control class defines the PreviewMouseDoubleClick and MouseDoubleClick events, but not corresponding single-click events. 若要查看用户是否已单击该控件一次,请处理该 MouseDown 事件 (或其对应的) 之一,并检查 ClickCount 属性值是否为1。To see if the user has clicked the control once, handle the MouseDown event (or one of its counterparts) and check whether the ClickCount property value is 1.

路由事件信息Routed Event Information

标识符字段Identifier field MouseDoubleClickEvent
路由策略Routing strategy 直接Direct
委托Delegate MouseButtonEventHandler

适用于