Mouse.PreviewMouseDown 附加事件

定义

当按下任何鼠标按钮时发生。Occurs when any mouse button is depressed.

see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler
see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler
see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler

注解

通过检查事件的参数来确定按下的鼠标按钮。Which mouse button was depressed is determined by checking the arguments of the event. 这是一个附加事件(使用隧道路由策略),该事件通过附加事件语法供接受输入的现有 用户界面 (UI)user interface (UI) 元素引用。This is an attached event (using tunneling routing strategy) that is intended through attached event syntax to be referenced by existing 用户界面 (UI)user interface (UI) elements that take input.

这是一个附加事件。This is an attached event. WPFWPF 将附加事件作为路由事件实现。implements attached events as routed events. 附加事件本质上是一种用于引用事件的 XAMLXAML 语言概念,这些事件可在未定义该事件的对象上进行处理,这 WPFWPF 通过同时启用事件来遍历路由来进行扩展。Attached events are fundamentally a XAMLXAML language concept for referencing events that can be handled on objects that do not define that event, which WPFWPF expands upon by also enabling the event to traverse a route. 附加事件在代码中没有直接处理语法;若要在代码中附加路由事件的处理程序,请使用指定的 Add * 处理程序方法。Attached events do not have a direct handling syntax in code; to attach handlers for a routed event in code, you use a designated Add*Handler method. 有关详细信息,请参阅附加事件概述For details, see Attached Events Overview.

Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 框架在此附加事件的基础上构建,方法是在 UIElement上将其作为两个不同的 公共语言运行时 (CLR)common language runtime (CLR) 事件进行呈现: PreviewMouseLeftButtonDownPreviewMouseRightButtonDownThe Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) framework builds on this attached event by surfacing it as two different 公共语言运行时 (CLR)common language runtime (CLR) events on UIElement: PreviewMouseLeftButtonDown and PreviewMouseRightButtonDown. 这些实现处理基础 PreviewMouseDown 事件并读取事件的参数,以确定是否涉及鼠标左键或右键。These implementations handle the underlying PreviewMouseDown event and read the arguments of the event to determine whether the left or right mouse button was involved. 对于三按钮,中间按钮没有框架级事件支持,应使用 PreviewMouseDown 事件并检查事件参数中的中间按钮条件。For three-button, there is no framework-level event support for the center button, and you should use the PreviewMouseDown event and check for the center button condition in the event arguments.

对于与鼠标相关的路由事件,请注意如何或何时将其标记为已处理。For routed events that relate to the mouse, be careful about how or when you mark them handled. 处理根附近的事件,并通过源进一步对源进行处理可能不适用于复合控件,其中的组合项可能具有预期的鼠标行为。Handling the event near the root and handling it by a child further toward the source may not be appropriate for composited controls, where the compositing pieces might have expected mouse behaviors. 如果对其他元素是否还应收到有关任何给定鼠标操作的相应选择做出适当的选择,则很难,因为这是因为 WPFWPF 框架选择了将基础 Mouse 路由事件呈现为沿路由 CLRCLR 事件的模型。The difficulty in making the appropriate choices about whether other elements should also be informed about any given mouse action is in fact why the WPFWPF framework chose the model of having the underlying Mouse routed event be surfaced as CLRCLR events along the route.

路由事件信息Routed Event Information

标识符字段Identifier field PreviewMouseDownEvent
路由策略Routing strategy 隧道Tunneling
委托Delegate MouseButtonEventHandler

适用于