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.

 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 架構層級基底元素,或在特別的情況下,針對每個元素定義資料指標行為並不符合您的需求,您應該只依賴 QueryCursorYou 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 - 委派Delegate QueryCursorEventHandler
  • 沒有已定義的對應通道事件。There is no defined corresponding tunneling event.

  • 覆寫 OnQueryCursor,以在衍生類別中為這個事件執行類別處理。Override OnQueryCursor to implement class handling for this event in derived classes.