UIElement.QueryCursor 事件

定义

当请求显示光标时发生。Occurs when the cursor is requested to display. 每次鼠标指针移至新位置时都会在一个元素上引发此事件,这意味着光标对象可能需要根据其新位置进行更改。This event is raised on an element each time that the mouse pointer moves to a new location, which means the cursor object might need to be changed based on its new position.

public:
 event System::Windows::Input::QueryCursorEventHandler ^ QueryCursor;
public event System.Windows.Input.QueryCursorEventHandler QueryCursor;
member this.QueryCursor : System.Windows.Input.QueryCursorEventHandler 
Public Custom Event QueryCursor As QueryCursorEventHandler 

注解

此事件创建此类的 Mouse.QueryCursor 附加事件的别名,以便在将 UIElement 作为基元素继承时,QueryCursor 是类成员列表的一部分。This event creates an alias for the Mouse.QueryCursor attached event for this class, so that QueryCursor is part of the class members list when UIElement is inherited as a base element. 附加到 QueryCursor 事件的事件处理程序附加到基础 Mouse.QueryCursor 附加事件,并接收相同的事件数据实例。Event handlers that are attached to the QueryCursor event are attached to the underlying Mouse.QueryCursor attached event and receive the same event data instance.

此事件名称所引用的游标不一定是文本光标(有时也称为插入点)。The cursor being referred to by this event name is not necessarily the text cursor (sometimes known as the insertion point). 相反,此上下文中的光标是一个对象,该对象声明与 Windows 编程中几个可能的输入相关设备或概念相关的屏幕图形显示。Instead, the cursor in this context is the object that declares the onscreen graphical display related to several possible input-related devices or concepts in Windows programming. 该对象由 WPF 中的 Cursor 类表示。That object is represented by the Cursor class in WPF. WPF 输入系统使你可以在其表示鼠标指针的屏幕位置时更改此光标。The WPF input system enables you to change this cursor when it represents the onscreen position of the mouse pointer. 可以从 Cursors 枚举使用预定义的值,也可以将自定义游标声明为映像文件。You can use predefined values from the Cursors enumeration, or you can declare a custom cursor as an image file.

侦听 QueryCursor 事件不是游标管理的有效方法。Listening for the QueryCursor event is not an efficient technique for cursor management. 相反,每个元素都应该定义自己的具有 CursorForceCursor的游标行为。Instead, each element should define its own cursor behavior with Cursor and ForceCursor. 仅当未使用 WPF 框架级别的基元素时,或在基于每个元素定义游标行为的特殊情况下,你应依赖于 QueryCursor,这不能满足你的需求。You should only rely on QueryCursor if you are not using the WPF framework-level base elements, or in extraordinary circumstances where defining cursor behavior on a per-element basis does not meet your needs. 有关实现游标行为以响应 QueryCursor的详细信息,请参阅 QueryCursorEventHandlerFor more information on implementing cursor behavior in response to QueryCursor, see QueryCursorEventHandler.

路由事件信息Routed Event Information

标识符字段Identifier field QueryCursorEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate QueryCursorEventHandler
  • 未定义相应的隧道事件。There is no defined corresponding tunneling event.

  • 重写 OnQueryCursor 在派生类中实现此事件的类处理。Override OnQueryCursor to implement class handling for this event in derived classes.

适用于

另请参阅