FrameworkElement.Cursor 屬性


取得或設定滑鼠指標在此元素上方時所顯示的游標。Gets or sets the cursor that displays when the mouse pointer is over this element.

 property System::Windows::Input::Cursor ^ Cursor { System::Windows::Input::Cursor ^ get(); void set(System::Windows::Input::Cursor ^ value); };
public System.Windows.Input.Cursor Cursor { get; set; }
member this.Cursor : System.Windows.Input.Cursor with get, set
Public Property Cursor As Cursor


要顯示的游標。The cursor to display. 預設值依這個相依性屬性定義為 nullThe default value is defined as null per this dependency property. 不過,執行階段的實際預設值會受各種因素影響。However, the practical default at run time will come from a variety of factors.


下列範例顯示如何刻意設定游標圖形。The following example shows how to deliberately set the cursor graphic.

private void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
    ComboBox source = e.Source as ComboBox;

    if (source != null)
        ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;

        // Changing the cursor of the Border control 
        // by setting the Cursor property
        switch (selectedCursor.Content.ToString())
            case "AppStarting":
                DisplayArea.Cursor = Cursors.AppStarting;
            case "ArrowCD":                        
                DisplayArea.Cursor = Cursors.ArrowCD;
            case "Arrow":
                DisplayArea.Cursor = Cursors.Arrow;
            case "Cross":
                DisplayArea.Cursor = Cursors.Cross;
            case "HandCursor":
                DisplayArea.Cursor = Cursors.Hand;
            case "Help":
                DisplayArea.Cursor = Cursors.Help;
            case "IBeam":
                DisplayArea.Cursor = Cursors.IBeam;
            case "No":
                DisplayArea.Cursor = Cursors.No;
            case "None":
                DisplayArea.Cursor = Cursors.None;
            case "Pen":
                DisplayArea.Cursor = Cursors.Pen;
            case "ScrollSE":
                DisplayArea.Cursor = Cursors.ScrollSE;
            case "ScrollWE":
                DisplayArea.Cursor = Cursors.ScrollWE;
            case "SizeAll":
                DisplayArea.Cursor = Cursors.SizeAll;
            case "SizeNESW":
                DisplayArea.Cursor = Cursors.SizeNESW;
            case "SizeNS":
                DisplayArea.Cursor = Cursors.SizeNS;
            case "SizeNWSE":
                DisplayArea.Cursor = Cursors.SizeNWSE;
            case "SizeWE":
                DisplayArea.Cursor = Cursors.SizeWE;
            case "UpArrow":
                DisplayArea.Cursor = Cursors.UpArrow;
            case "WaitCursor":
                DisplayArea.Cursor = Cursors.Wait;
            case "Custom":
                DisplayArea.Cursor = CustomCursor;

        // If the cursor scope is set to the entire application
        // Use OverrideCursor to force the cursor for all elements
        if (cursorScopeElementOnly == false)
            Mouse.OverrideCursor = DisplayArea.Cursor;
' When the Radiobox changes, a new cursor type is set
Private Sub CursorTypeChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)

    Dim item As String = CType(e.Source, ComboBox).SelectedItem.Content.ToString()

    Select Case item
        Case "AppStarting"
            DisplayArea.Cursor = Cursors.AppStarting
        Case "ArrowCD"
            DisplayArea.Cursor = Cursors.ArrowCD
        Case "Arrow"
            DisplayArea.Cursor = Cursors.Arrow
        Case "Cross"
            DisplayArea.Cursor = Cursors.Cross
        Case "HandCursor"
            DisplayArea.Cursor = Cursors.Hand
        Case "Help"
            DisplayArea.Cursor = Cursors.Help
        Case "IBeam"
            DisplayArea.Cursor = Cursors.IBeam
        Case "No"
            DisplayArea.Cursor = Cursors.No
        Case "None"
            DisplayArea.Cursor = Cursors.None
        Case "Pen"
            DisplayArea.Cursor = Cursors.Pen
        Case "ScrollSE"
            DisplayArea.Cursor = Cursors.ScrollSE
        Case "ScrollWE"
            DisplayArea.Cursor = Cursors.ScrollWE
        Case "SizeAll"
            DisplayArea.Cursor = Cursors.SizeAll
        Case "SizeNESW"
            DisplayArea.Cursor = Cursors.SizeNESW
        Case "SizeNS"
            DisplayArea.Cursor = Cursors.SizeNS
        Case "SizeNWSE"
            DisplayArea.Cursor = Cursors.SizeNWSE
        Case "SizeWE"
            DisplayArea.Cursor = Cursors.SizeWE
        Case "UpArrow"
            DisplayArea.Cursor = Cursors.UpArrow
        Case "WaitCursor"
            DisplayArea.Cursor = Cursors.Wait
        Case "Custom"
            DisplayArea.Cursor = CustomCursor
    End Select

    ' if the cursor scope is set to the entire application
    ' use OverrideCursor to force the cursor for all elements
    If (cursorScopeElementOnly = False) Then
        Mouse.OverrideCursor = DisplayArea.Cursor
    End If

End Sub


當您在 XAMLXAML中設定這個屬性時,XAMLXAML 處理器會依賴 Cursor 類別的型別轉換來評估字串。When you set this property in XAMLXAML, the XAMLXAML processor relies on type conversion for the Cursor class to evaluate the string. 提供的字串應該評估為 CursorType 值。The provided string should evaluate to a CursorType value. 如需詳細資訊,請參閱<Cursor>。See Cursor for details.

當滑鼠指標在此元素上方時,這個屬性所建立的游標是否將會顯示,也會相依于 ForceCursor 屬性的值。Whether the cursor as established by this property will or will not display when the mouse pointer is over this element is also dependent on the value of the ForceCursor property. 此外,事件相關的考慮(例如,使用中的拖曳、滑鼠捕捉、控制項內的文字編輯模式等等)也會影響優先順序高於您在此屬性中指定之值的資料指標。Also, event-related considerations such as an active drag, mouse capture, text editing modes within controls, and so on, will also affect the cursor with higher priority than the value you specify in this property.

若要還原將此屬性設定為最終預設值的行為,請將它設定為 [null]。To revert the behavior of setting this property to the eventual default, set it to null again.

null 預設值,實際上表示判斷實際的資料指標值會在這裡延遲,而且應該從其他地方取得。The null default really means that determination of the practical cursor value is deferred here and should be obtained from elsewhere. 如果在沒有任何來源的程式設計值的情況下顯示,則會以視覺方式在 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 應用程式上呈現的預設游標為箭號。If presented without programmatic values from any source, the default cursor that is visually over a Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) application will be an arrow. 不過,暫時性資料指標變更在傳遞時不會設定為元素的 Cursor 值。However, the transient cursor changes are not set to the Cursor values of the elements when they are passed over. 只有在實際設定(例如透過程式碼或樣式)時,Cursor 屬性才會報告非 null 值。The Cursor property will only report non null values in cases where it was actually set, for instance through code or a style. 將滑鼠移到 WPFWPF 應用程式上的每個動作都會引發 QueryCursor 事件。Each movement of the mouse over a WPFWPF application raises a QueryCursor event. 事件會冒泡,而路由中的任何元素都有機會處理事件,並透過這個事件的引數設定資料指標的值。The event bubbles, and any element along the route has the opportunity to handle the event and to set the value of the cursor through the arguments of this event. 在大部分情況下,這是產生視覺效果明顯資料指標的機制。This is the mechanism that produces the visually apparent cursor in most cases. 如果 QueryCursor 處理常式傳回資料指標結果,則在引數中處理事件並具有變更值的事實,會優先于任何層級的 Cursor 屬性值,除非已設定 ForceCursorIf a QueryCursor handler returns a cursor result, then the fact that the event is handled and has a changed value in the arguments takes precedence over the value of the Cursor property at any level, unless ForceCursor is set.

如果不是建立自訂資料指標,您通常會將此屬性設定為 Cursors 類別的靜態屬性值。If not are not creating a custom cursor, you typically set this property to a static property value of the Cursors class. 在程式碼中設定 Cursor 需要下列其中一項:Setting Cursor in code requires one of the following:

在部分信任中,不會啟用將 Cursor 設定為自訂值。Setting the Cursor to a custom value is not enabled in partial trust. 如需自訂資料指標的詳細資訊,請參閱輸入總覽For more information on custom cursors, see Input Overview.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field CursorProperty
設定為 true 的中繼資料屬性Metadata properties set to true NoneNone