Dela via


CoreCursor Class

Definition

Defines a cursor (visual pointer) object.

public ref class CoreCursor sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.Core.ICoreCursorFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreCursor final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.Core.ICoreCursorFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class CoreCursor final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.Core.ICoreCursorFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreCursor
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.Core.ICoreCursorFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class CoreCursor
Public NotInheritable Class CoreCursor
Inheritance
Object Platform::Object IInspectable CoreCursor
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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)

Creates a new CoreCursor instance of the provided cursor type.

Properties

Id

Gets the resource ID of the cursor.

Type

Gets the type of the cursor.

Applies to