Control.MouseDoubleClick 事件

定義

發生於按兩下或更多下滑鼠按鈕時。

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 

事件類型

範例

下列範例示範如何將事件處理常式附加至 MouseDoubleClick 事件。

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

下列範例顯示 事件的事件處理常式 MouseDoubleClick

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

備註

雖然這個路由事件似乎遵循元素樹狀結構中的反升路由,但實際上是由每個 UIElement 沿著元素樹狀結構引發的直接路由事件。 如果您在事件處理常式中 MouseDoubleClickHandled 屬性設定為 true ,則路由上的後續 MouseDoubleClick 事件將會設定 Handledfalse 。 這是較高層級事件,適用于想要在使用者按兩下控制項並處理應用程式中事件的控制項取用者。

當 等於 2 時 ClickCount ,控制想要處理滑鼠按兩下的作者應該使用 MouseLeftButtonDown 事件。 當專案樹狀結構中的另一個專案處理事件時,這會導致 的狀態 Handled 適當地傳播。

類別 ControlPreviewMouseDoubleClick 定義 和 MouseDoubleClick 事件,但不會定義對應的單鍵事件。 若要查看使用者是否已按一下控制項一次,請處理 MouseDown 事件 (或其對應的其中一個) ,並檢查屬性值是否 ClickCount 為 1。

路由事件資訊

識別碼欄位 MouseDoubleClickEvent
路由策略 直接
代理人 MouseButtonEventHandler

適用於