ContentElement.OnMouseLeftButtonDown(MouseButtonEventArgs) 方法


当此元素引发未处理的 MouseLeftButtonDown 路由事件时调用。Invoked when an unhandled MouseLeftButtonDown routed event is raised on this element. 实现此方法可为此事件添加类处理。Implement this method to add class handling for this event.

protected public:
 virtual void OnMouseLeftButtonDown(System::Windows::Input::MouseButtonEventArgs ^ e);
protected internal virtual void OnMouseLeftButtonDown (System.Windows.Input.MouseButtonEventArgs e);
abstract member OnMouseLeftButtonDown : System.Windows.Input.MouseButtonEventArgs -> unit
override this.OnMouseLeftButtonDown : System.Windows.Input.MouseButtonEventArgs -> unit
Protected Friend Overridable Sub OnMouseLeftButtonDown (e As MouseButtonEventArgs)



包含事件数据的 MouseButtonEventArgsThe MouseButtonEventArgs that contains the event data. 事件数据报告称已按下鼠标左键。The event data reports that the left mouse button was pressed.


MouseLeftButtonDown事件看起来像是以冒泡路线旅行,但实际以间接方式传播。The MouseLeftButtonDown event appears to travel a bubbling route but actually travels in an indirect way. Mouse.MouseDown 是进行冒泡路由的基础事件,每个 ContentElement 事件路由沿事件路由都使用相同的处理来引发直接路由事件 MouseLeftButtonDownMouse.MouseDown is the underlying event that is bubble routed, and each ContentElement along the event route uses identical handling to raise the direct routed event MouseLeftButtonDown. 虽然您可以将 MouseLeftButtonDown 事件标记为已处理,以便进行此元素,但已处理状态并不保持事件路由中的其他元素。Although you can mark the MouseLeftButtonDown event as handled for purposes of this element, the handled state does not perpetuate to other elements along the event route. 但是,你可能需要将事件标记为已处理,以防止常规实例处理程序 (未指定调用) 的实例处理程序 handledEventsTooHowever, you might want to mark the event as handled in order to prevent general instance handlers (those that did not specify handledEventsToo) from being invoked.

中的常规鼠标事件处理的默认实现 ContentElement 将侦听 Mouse.MouseDown 并将其转换为适当的本地事件。The default implementation for general mouse event handling in ContentElement listens for Mouse.MouseDown and converts it to an appropriate local event. 如果要重写此逻辑,必须创建派生类。If you want to override this logic, you must create a derived class. 在派生类的静态构造函数中,为注册替代类处理程序 Mouse.MouseDownIn the static constructor of your derived class, register an alternative class handler for Mouse.MouseDown. 不能 ContentElement 通过重写来更改的鼠标处理行为 OnMouseLeftButtonDownYou cannot change the mouse handling behavior of ContentElement by overriding OnMouseLeftButtonDown.

或者,您可以重写此方法,以便为特定的鼠标状态更改事件处理。Alternatively, you can override this method in order to change event handling for a specific mouse state. 是否选择调用基实现取决于方案。Whether you choose to call the base implementation depends on your scenario. 如果无法调用 base,将禁用对也需要调用的上级类上的鼠标事件的默认输入处理 OnMouseLeftButtonDownFailing to call base disables default input handling for that mouse event on ancestor classes that also expect to invoke OnMouseLeftButtonDown. 例如,你可以 Button OnMouseLeftButtonDown 在派生类中派生,而不调用基实现; 但是,此重写将禁用 Click 事件。For example, you can derive from Button and override OnMouseLeftButtonDown in your derived class without calling the base implementation; however, this override disables the Click event.