UIElement.MouseLeftButtonDown UIElement.MouseLeftButtonDown UIElement.MouseLeftButtonDown UIElement.MouseLeftButtonDown Event

定义

在鼠标指针位于此元素上并且按下鼠标左键时发生。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. 这可能包括类处理程序生成的事件, MouseDoubleClick例如。This 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. 对于更高级的方案, 如检查非标准按钮的状态, 可能需要APIAPIs Mouse在类而不是上UIElement使用。For more advanced scenarios, such as checking for states of non-standard buttons, you might need to use the APIAPIs 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并选择允许处理程序侦听事件的签名选项 (即使它们已在路由事件数据中标记为已处理), 在控件过程上注册处理程序。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 MouseButtonEventHandler

适用于

另请参阅