UIElement.MouseLeftButtonDown 事件

定義

滑鼠指標在此元素上方且按下滑鼠左按鈕時發生。Occurs when the left mouse button is pressed while the mouse pointer is over this element.

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

實作

備註

雖然此路由事件似乎會遵循透過專案樹狀結構的反升路由,但實際上是直接路由事件,每個 UIElement都會沿著元素樹狀結構引發並 reraised。Although this routed event seems to follow a bubbling route through an element tree, it actually is a direct routed event that is raised and reraised along the element tree by each UIElement.

這個事件是數個相關事件的其中一個,可報告基礎 Mouse.MouseDown 事件的滑鼠按鍵細節,這是一個附加事件,會沿著事件路由中的每個元素來處理。This event is one of several related events that report the mouse-button specifics of an underlying Mouse.MouseDown event, which is an attached event that is processed by each element along an event route.

此事件的事件資料會公開基礎 Mouse.MouseDown 事件的事件資料。The event data of this event exposes the event data of the underlying Mouse.MouseDown event. 如果該事件標示為沿著事件路由處理,則仍然會引發滑鼠按鍵特定事件;不過,必須藉由明確地呼叫 AddHandler來加入滑鼠按鍵特定事件的處理常式,並使用選項來處理已標示為已處理的事件,以便成為事件的接聽項。If that event is marked as handled along the event route, the mouse-button specific events are still raised; however, handlers of the mouse-button specific events must be added by explicitly calling AddHandler, with the option to handle events that are already marked as handled, in order to be listeners to the event. 如果您將 MouseLeftButtonDown 標示為已處理,則基本上會將路由中的所有其他接聽程式以及所有相關事件的 Mouse.MouseDown 都標示為已處理。If you mark MouseLeftButtonDown handled, you are essentially marking Mouse.MouseDown handled for all further listeners along the route, and on all related events. 這可能包括類別處理常式產生的事件,例如 MouseDoubleClickThis possibly includes class-handler generated events such as MouseDoubleClick.

在概念上,請將這個事件(以及 UIElement上的其他滑鼠按鍵事件)視為滑鼠「服務」(具有 Mouse 類別所提供的服務定義)。Conceptually, think of this event (and other mouse-button events on UIElement) to be a mouse "service" (with the service definition provided by the Mouse class). 事件會增加不需要檢查事件資料中原始滑鼠事件的滑鼠按鍵狀態(由左至右、上下)的便利性。The event adds the convenience of not needing to check the mouse button states (left-right, up-down) of the original mouse events in the event data. 針對更先進的案例,例如檢查非標準按鈕的狀態,您可能需要在 Mouse 類別上使用 Api,而不是 UIElement上的應用程式開發介面。For more advanced scenarios, such as checking for states of non-standard buttons, you might need to use the APIs on the Mouse class rather than those on UIElement.

重要

某些控制項類別可能會有滑鼠按鍵事件的固有類別處理。Some control classes might have inherent class handling for mouse button events. 滑鼠左鍵向下鍵是在控制項中具有類別處理的最可能事件。The left mouse button down event is the most likely event to have class handling in a control. 類別處理通常會將基礎 Mouse 類別事件標示為已處理。The class handling often marks the underlying Mouse class event as handled. 一旦將事件標示為已處理,通常不會引發附加至該元素的其他實例處理常式。Once the event is marked handled, other instance handlers that are attached to that element are not ordinarily raised. 任何其他附加至 UI 樹狀結構中的根項目的類別或實例處理常式,通常也不會引發。Any other class or instance handlers that are attached to elements in the bubbling direction towards the root in the UI tree are also not ordinarily raised.

您可以使用下列其中一種解決方案,解決先前重要的問題,並在具有類別處理的衍生類別上,以滑鼠左鍵停止事件的 MouseLeftButtonDown 事件:You can resolve the issue that is outlined in the preceding Important and still receive MouseLeftButtonDown events for left mouse button down events on a derived class that has class handling by using either of these solutions:

  • 附加 PreviewMouseDown 事件的處理常式,但未標示為由控制項處理。Attach handlers for the PreviewMouseDown event, which is not marked as handled by the controls. 請注意,因為這是預覽事件,所以路由會從根節點開始,並向下通道至控制項。Notice that because this is a preview event, the route starts at the root and tunnels down to the control.

  • 藉由呼叫 AddHandler 並選擇可讓處理常式接聽事件的簽章選項(即使已在路由事件資料中標示為已處理),在控制項 cti 上註冊處理常式。Register a handler on the control procedurally by calling AddHandler and choosing the signature option that enables handlers to listen for events even if they are already marked as handled in the routed event data.

路由事件資訊Routed Event Information

識別碼欄位Identifier field MouseLeftButtonDownEvent
路由策略Routing strategy 直接Direct
Delegate - 委派Delegate MouseButtonEventHandler

適用於

另請參閱