FrameworkElement.Cursor FrameworkElement.Cursor FrameworkElement.Cursor FrameworkElement.Cursor Property

定義

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

public:
 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;
                break;
            case "ArrowCD":                        
                DisplayArea.Cursor = Cursors.ArrowCD;
                break;
            case "Arrow":
                DisplayArea.Cursor = Cursors.Arrow;
                break;
            case "Cross":
                DisplayArea.Cursor = Cursors.Cross;
                break;
            case "HandCursor":
                DisplayArea.Cursor = Cursors.Hand;
                break;
            case "Help":
                DisplayArea.Cursor = Cursors.Help;
                break;
            case "IBeam":
                DisplayArea.Cursor = Cursors.IBeam;
                break;
            case "No":
                DisplayArea.Cursor = Cursors.No;
                break;
            case "None":
                DisplayArea.Cursor = Cursors.None;
                break;
            case "Pen":
                DisplayArea.Cursor = Cursors.Pen;
                break;
            case "ScrollSE":
                DisplayArea.Cursor = Cursors.ScrollSE;
                break;
            case "ScrollWE":
                DisplayArea.Cursor = Cursors.ScrollWE;
                break;
            case "SizeAll":
                DisplayArea.Cursor = Cursors.SizeAll;
                break;
            case "SizeNESW":
                DisplayArea.Cursor = Cursors.SizeNESW;
                break;
            case "SizeNS":
                DisplayArea.Cursor = Cursors.SizeNS;
                break;
            case "SizeNWSE":
                DisplayArea.Cursor = Cursors.SizeNWSE;
                break;
            case "SizeWE":
                DisplayArea.Cursor = Cursors.SizeWE;
                break;
            case "UpArrow":
                DisplayArea.Cursor = Cursors.UpArrow;
                break;
            case "WaitCursor":
                DisplayArea.Cursor = Cursors.Wait;
                break;
            case "Custom":
                DisplayArea.Cursor = CustomCursor;
                break;
            default:
                break;
        }

        // 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. 如需詳細資訊,請參閱CursorSee 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處理常式傳回一個資料指標結果,則事件處理,而且引數中已變更的值優先於 windows 7Cursor屬性,在任何層級,除非ForceCursor設定。If 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
若要設定的中繼資料屬性 trueMetadata properties set to true None

適用於

另請參閱