ContentElement.MouseDown 事件


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

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




這個事件 Mouse.MouseDown 會為這個類別建立附加事件的別名,因此 MouseDownContentElement 繼承為基底專案時,就是類別成員清單的一部分。This event creates an alias for the Mouse.MouseDown attached event for this class, so that MouseDown is part of the class members list when ContentElement is inherited as a base element. 附加至事件的事件處理常式 MouseDown 會附加至基礎 Mouse.MouseDown 附加事件,並接收相同的事件資料實例。Event handlers that are attached to the MouseDown event are attached to the underlying Mouse.MouseDown attached event and receive the same event data instance.

MouseDown事件通常會與或一起引發 MouseLeftButtonDown MouseRightButtonDown ,其對應至兩個標準滑鼠按鍵的其中一個。The MouseDown event is often raised together with either MouseLeftButtonDown or MouseRightButtonDown, which correspond to a press of one of the two standard mouse buttons. MouseLeftButtonDownMouseRightButtonDown 也是路由事件,但它們是直接路由事件,當 Mouse.MouseDown 事件在事件路由中到達這個專案時,就會引發適當的按鈕特定事件。MouseLeftButtonDown and MouseRightButtonDown are also routed events, but they are direct routed events, and the appropriate button-specific event is raised when the Mouse.MouseDown event reaches this element along the event route. 請參閱或的備註 MouseLeftButtonDown MouseRightButtonDownSee Remarks for MouseLeftButtonDown or MouseRightButtonDown.


有些 ContentElement 具有類似控制項行為的衍生類別(例如), Hyperlink 可能會有滑鼠按鍵事件的固有類別處理。A few ContentElement derived classes that have control-like behavior, for example, Hyperlink, 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.

您可以使用下列其中一種解決方案,解決先前的重要事件中所述的問題,而且在 MouseDown 具有類別處理的衍生類別上,仍會收到滑鼠左鍵的事件:You can resolve the issue that is outlined in the preceding Important and still receive MouseDown 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 MouseDownEvent
路由策略Routing strategy 路由Bubbling
代理人Delegate MouseButtonEventHandler