UIElement.OnPreviewMouseLeftButtonDown(MouseButtonEventArgs) 方法

定义

当某个未处理的 PreviewMouseLeftButtonDown 路由事件在其路由中到达派生自此类的某个元素时调用。Invoked when an unhandled PreviewMouseLeftButtonDown routed event reaches an element in its route that is derived from this class. 实现此方法可为此事件添加类处理。Implement this method to add class handling for this event.

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

参数

e
MouseButtonEventArgs

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

注解

"PreviewMouseLeftButtonDown" 事件显示为传送隧道路由,但实际以间接方式传播。The PreviewMouseLeftButtonDown event appears to travel a tunneling route but actually travels in an indirect way. Mouse.PreviewMouseDown 是作为隧道路由的基础事件,并且事件路由中的每个 UIElement 使用相同的处理来引发直接路由事件 PreviewMouseLeftButtonDownMouse.PreviewMouseDown is the underlying event that is tunnel routed, and each UIElement along the event route uses identical handling to raise the direct routed event PreviewMouseLeftButtonDown. 虽然您可以将 PreviewMouseLeftButtonDown 事件标记为为此元素的目的进行处理,但已处理状态并不会与事件路由中的其他元素保持。Although you can mark the PreviewMouseLeftButtonDown event as handled for purposes of this element, the handled state does not perpetuate to other elements along the event route. 但是,你可能需要将事件标记为已处理,以防止调用常规实例处理程序(未指定 handledEventsToo)。However, 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.

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

或者,您可以重写此方法,以便为特定的鼠标状态更改事件处理。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,则会禁用上级类上对该鼠标事件的默认输入处理,这也会要求调用 OnPreviewMouseLeftButtonDownFailing to call base disables default input handling for that mouse event on ancestor classes that also expect to invoke OnPreviewMouseLeftButtonDown. 例如,你可以在派生类中派生 Button 和重写 OnPreviewMouseLeftButtonDown,而无需调用基实现;但是,此替代禁用 Click 事件。For example, you can derive from Button and override OnPreviewMouseLeftButtonDown in your derived class without calling the base implementation; however, this override disables the Click event.

适用于