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. 有关更多信息,请参见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 处理程序返回游标结果,则处理事件并在参数中具有更改的值将优先于任何级别的 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
元数据属性设置为 trueMetadata properties set to true None