CoreCursor CoreCursor CoreCursor CoreCursor Class

Definition

Defines a cursor (visual pointer) object.

public : sealed class CoreCursor : ICoreCursor
struct winrt::Windows::UI::Core::CoreCursor : ICoreCursor
public sealed class CoreCursor : ICoreCursor
Public NotInheritable Class CoreCursor Implements ICoreCursor
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

This example shows how to set a "hand" cursor when the pointer is over a button.

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Button Content="Button 1"
            PointerEntered="Button_PointerEntered"
            PointerExited="Button_PointerExited"/>
</Grid>
public sealed partial class MainPage : Page
{
    CoreCursor buttonCursor = null;
    CoreCursor cursorBeforePointerEntered = null;

    public MainPage()
    {
        this.InitializeComponent();
        buttonCursor = new CoreCursor(CoreCursorType.Hand, 0);
    }

    private void Button_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        // Cache the cursor set before pointer enter on button.
        cursorBeforePointerEntered = Window.Current.CoreWindow.PointerCursor;
        // Set button cursor.
        Window.Current.CoreWindow.PointerCursor = buttonCursor;
    }

    private void Button_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        // Change the cursor back.
        Window.Current.CoreWindow.PointerCursor = cursorBeforePointerEntered;
    }
}

Remarks

To create a CoreCursor instance using a pre-defined Windows cursor, use any of the cursor types available in the CoreCursorType enumeration other than Custom. In this case, the Id property is ignored.

To use a custom cursor, use the CoreCursorType.Custom enumeration option, and specify the Id of the custom cursor. You can add a .res resource file that contains the custom cursor to your project and include it in your assembly with the /win32res compiler option. The Id is the Cursor Resource ID specified in the .res file.

Constructors

CoreCursor(CoreCursorType, UInt32) CoreCursor(CoreCursorType, UInt32) CoreCursor(CoreCursorType, UInt32) CoreCursor(CoreCursorType, UInt32)

Creates a new CoreCursor instance of the provided cursor type.

Properties

Id Id Id Id

Gets the resource ID of the cursor.

Type Type Type Type

Gets the type of the cursor.