Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FrameworkContentElement.Cursor Property

Gets or sets the cursor that displays when the mouse pointer is over this element.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public Cursor Cursor { get; set; }
<object Cursor="Cursor" .../>

Property Value

Type: System.Windows.Input.Cursor
The cursor to display. The default value is defined as null per this dependency property. However, the practical default at run time will come from a variety of factors.

Identifier field

CursorProperty

Metadata properties set to true

None

When setting this property in XAML, the XAML processor relies on type conversion for the Cursor class to evaluate the string. The provided string should evaluate to a CursorType value. See Cursor for details.

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.

To revert the behavior of setting this property to the eventual default, set it to null again.

The null default really means that determination of the practical cursor value is deferred here and should be obtained from elsewhere. If presented with no programmatic values from any source, the default cursor over a Windows Presentation Foundation (WPF) application will be an arrow.

Each movement of the mouse over a WPF 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 via the arguments of this event. If that happens, 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.

If not creating a custom cursor, typically you set this property to a static property value of the Cursors class.

Setting the Cursor to a custom value is not enabled in partial trust. For more information on custom cursors, see Input Overview.

The following example sets the cursor to a custom value.

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;
        }
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.