Control.MouseDoubleClick Event

Definition

發生於按兩下或更多下滑鼠按鈕時。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 

Examples

下列範例顯示如何將事件處理常式附加至 MouseDoubleClick 事件。The following example shows how to attach an event handler to the MouseDoubleClick event.

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

下列範例顯示 MouseDoubleClick 事件的事件處理常式。The 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

Remarks

雖然此路由事件似乎會遵循透過專案樹狀結構的反升路由,但實際上是直接路由事件,會隨著每個 UIElement沿著元素樹狀結構引發。Although 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. 如果您在 MouseDoubleClick 事件處理常式中將 Handled 屬性設定為 true,則會沿著路由進行後續 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.

ClickCount 等於2時,想要處理滑鼠按兩下動作的控制項作者應該使用 MouseLeftButtonDown 事件。Control 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

Applies to