Control.PreviewMouseDoubleClick 事件
定義
使用者按滑鼠按鈕超過兩下時發生。Occurs when a user clicks the mouse button two or more times.
public:
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="ChangeForeground">
Foreground
</Button>
下列範例會顯示事件的事件處理常式 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";
}
else
{
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"
Else
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. 如果您在 Handled 事件處理常式中將屬性設定為,則 true
PreviewMouseDoubleClick PreviewMouseDoubleClick 沿著路由的後續事件將會在設定為的情況下發生 Handled false
,但 MouseDoubleClick 會在設定為時發生事件 Handled true
。If 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.
PreviewMouseLeftButtonDown當等於兩個時,想要處理滑鼠按兩下動作的控制項作者應該使用事件 ClickCount 。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類別 PreviewMouseDoubleClick 會定義和 MouseDoubleClick 事件,但不會定義對應的單鍵事件。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 |