Control.PreviewMouseDoubleClick Event


在用户单击鼠标按钮两次或更多次时发生。Occurs when a user clicks the mouse button two or more times.

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


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

<Button Name="btn1" Foreground="Black" 

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

void ChangeForeground(object sender, RoutedEventArgs e)
    if (btn1.Foreground == Brushes.Green)
        btn1.Foreground = Brushes.Black;
        btn1.Content = "Foreground";
        btn1.Foreground = Brushes.Green;
        btn1.Content = "Control foreground(text) changes from black to green.";
Private Sub ChangeForeground(ByVal Sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)

    If (btn1.Foreground Is Brushes.Green) Then
        btn1.Foreground = Brushes.Black
        btn1.Content = "Foreground"
        btn1.Foreground = Brushes.Green
        btn1.Content = "Control foreground(text) changes from black to green."
    End If

End Sub


尽管此路由事件看起来是通过元素树跟踪隧道路由,但实际上它是由每个 UIElement沿元素树引发的直接路由事件。Although this routed event seems to follow a tunneling route through an element tree, it actually is a direct routed event that is raised along the element tree by each UIElement. 如果在 PreviewMouseDoubleClick 事件处理程序中将 Handled 属性设置为 "true,则在 Handled 设置为 false时,将发生沿路由的后续 PreviewMouseDoubleClick 事件,但 MouseDoubleClick 事件发生时将 Handled 设置为 trueIf you set the Handled property to true in a PreviewMouseDoubleClick event handler, subsequent PreviewMouseDoubleClick events along the route will occur with Handled set to false, but the MouseDoubleClick event will occur with Handled set to true. 这是控件使用者的高级事件,当用户双击控件并处理应用程序中的事件时,这些用户希望获得通知。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.

ClickCount 等于2时,要处理鼠标双击的控件作者应使用 PreviewMouseLeftButtonDown 事件。Control authors who want to handle mouse double clicks should use the PreviewMouseLeftButtonDown 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 PreviewMouseDoubleClickEvent
路由策略Routing strategy 直接Direct
委托Delegate MouseButtonEventHandler

Applies to