UIElement.MouseDown UIElement.MouseDown UIElement.MouseDown UIElement.MouseDown Event

定义

在指针位于此元素上并且按下任意鼠标按钮时发生。Occurs when any mouse button is pressed while the pointer is over this element.

public:
 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附加事件的别名, 因此当继承MouseDown为基元素时UIElement , 它是类成员列表的一部分。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 UIElement 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.

事件通常MouseLeftButtonDown与或MouseRightButtonDown一起引发, 这对应于按下这两个标准鼠标按钮之一。 MouseDownThe 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 MouseRightButtonDown的 "备注"。See Remarks for MouseLeftButtonDown or MouseRightButtonDown.

重要

某些控件可能具有鼠标按钮事件的固有类处理。Some controls 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并选择允许处理程序侦听事件的签名选项 (即使它们已在路由事件数据中标记为已处理), 在控件过程上注册处理程序。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

适用于