UIElement.OnPreviewMouseUp(MouseButtonEventArgs) UIElement.OnPreviewMouseUp(MouseButtonEventArgs) UIElement.OnPreviewMouseUp(MouseButtonEventArgs) UIElement.OnPreviewMouseUp(MouseButtonEventArgs) Method

定义

当某个未处理的 PreviewMouseUp 附加事件在其路由中到达派生自此类的某个元素时调用。Invoked when an unhandled PreviewMouseUp attached 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 OnPreviewMouseUp(System::Windows::Input::MouseButtonEventArgs ^ e);
protected virtual void OnPreviewMouseUp (System.Windows.Input.MouseButtonEventArgs e);
abstract member OnPreviewMouseUp : System.Windows.Input.MouseButtonEventArgs -> unit
override this.OnPreviewMouseUp : System.Windows.Input.MouseButtonEventArgs -> unit
Protected Overridable Sub OnPreviewMouseUp (e As MouseButtonEventArgs)

参数

e
MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs

包含事件数据的 MouseButtonEventArgsThe MouseButtonEventArgs that contains the event data. 事件数据将报告已释放了一个或多个鼠标按钮。The event data reports that one or more mouse buttons were released.

注解

鼠标按钮操作也由专用的输入管理器进行处理。Mouse button actions are also handled by a dedicated input manager. 依赖于鼠标按钮操作的其他编程功能 (如输入和命令绑定) 可能会调用操作的处理程序, 然后才能将其作为常规鼠标按钮操作公开。Other programming features that rely on mouse button actions, such as input and command bindings, might invoke handlers for the action before it is exposed as a general mouse button action. 如果这些输入系统功能将Mouse.PreviewMouseUp事件标记为已处理, OnPreviewMouseUp则不会调用。If these input system features mark the Mouse.PreviewMouseUp event as handled, OnPreviewMouseUp is not invoked.

如果使用此类处理程序将事件标记为已处理, 则可能会影响以下事件: PreviewMouseLeftButtonUpPreviewMouseRightButtonUpIf you use this class handler to mark the event as handled, you potentially impact the following events: PreviewMouseLeftButtonUp and PreviewMouseRightButtonUp. 收到时Mouse.PreviewMouseUp , 可能会在接收元素上引发这些事件中的任何一个。Either of these events might be raised on the receiving element when Mouse.PreviewMouseUp is received.

如果将此事件标记为 "在类处理中处理", 则仍会引发 subevents;但是, 它们将在事件数据中传递已处理状态。If you mark this event as handled in class handling, subevents are still raised; however, they pass the handled state in the event data. 如果在类处理中处理该事件, 则不会调用 subevents 的实例处理程序, 除非您AddHandler(RoutedEvent, Delegate, Boolean)显式handledEventsToo使用 with true以便附加处理程序。If the event is handled in class handling, instance handlers for the subevents are not invoked unless you explicitly use AddHandler(RoutedEvent, Delegate, Boolean) with handledEventsToo true in order to attach handlers. 类处理程序也不会被调用, 除非这些类处理程序RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean)已注册handledEventsTootrue签名。Class handlers also are not invoked unless those class handlers were registered with the RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) signature with handledEventsToo true. 通过处理OnPreviewMouseUp, 可以确保类处理对所有可能的鼠标按钮向上操作都进行处理。By handling OnPreviewMouseUp, you are implying that your class handling accounted for all possible mouse button up actions. 此行为可能不是必需的;因此, 使用此虚方法将事件标记为已处理时, 请谨慎使用。This behavior might be unwanted; Therefore, use caution when you use this virtual method to mark events as handled.

每个特定于按钮的直接事件还具有一个虚拟 On * 方法;考虑是否可以更适当地重写这些按钮特定的类处理程序。Each of the button-specific direct events also has a virtual On* method; consider whether overriding these button-specific class handlers might be more appropriate.

此方法没有默认实现。This method has no default implementation. 因为继承中的中间类可能实现此方法, 所以建议您在实现中调用基实现。Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

此方法的用途类似于 * 方法上公共语言运行时 (CLR)common language runtime (CLR)的事件模式: 此方法提供了通过建立类处理程序而不是实例处理程序来处理来自派生类的匹配事件的方法。The purpose of this method is similar to the 公共语言运行时 (CLR)common language runtime (CLR) event pattern On* methods: this method provides the means to handle the matching event from derived classes by establishing a class handler instead of an instance handler. 在这种情况下, 匹配事件是路由事件。In this case the matching event is a routed event. 对于路由事件, On * 方法的实现模式是不同的, 因为路由事件可以由子元素引发, 这不一定是将调用处理程序的元素。The implementation pattern of the On* methods is different for routed events because a routed event can be raised by a child element, which is not necessarily the element that will invoke handlers. 因此, 您的实现需要检查事件数据的源属性。Therefore, your implementation needs to examine the source properties of the event data. 大多数情况下, 它不应尝试 reraise 该事件。It should not try to reraise the event in most cases.

通过重写此方法或使用RegisterClassHandler注册类处理程序, UIElement可以在事件路由中收到事件时调用私有类处理程序方法。Either by overriding this method or by registering class handlers with RegisterClassHandler, derived classes of UIElement can call private class handler methods when the event is received along the event route. 适用于类处理的一种情况是操作事件数据, 并将路由事件标记为 "已处理"。One scenario where class handling is appropriate is to manipulate the event data and mark the routed event as handled.

适用于

另请参阅