Reputation: 23
As far as I know "Cursor" don't exits in UWP.
I can change cursor with this code:
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0);
How do I create a custom cursor with CoreCursorType.Custom?
CoreCursorType.Custom
Upvotes: 2
Views: 1325
Reputation: 37633
Here is the answer https://learn.microsoft.com/en-us/uwp/api/windows.ui.core.corecursor?view=winrt-20348
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.
Personally I have used this working manual https://social.msdn.microsoft.com/Forums/en-US/14001796-bcd5-4b9d-9d7e-13bc6ba59d2d/uwp-how-to-set-a-pointer-cursor-as-a-circle-instead-of-a-window-default-cursor?forum=wpdevelop
We need just proper .res
file
For that we should do following
Create any C++ project. For example Dll, Add new C++ Dll project name it for example as ResourcesComponent.
Add a resource file to the project. [right-mouse] the project name "ResourcesComponent" => Add New Item => Visual C++ => Resource File (.rc)
Name the resource file for example Resources.rc
Add a cursor resource. Double click on Resources.rc
the it will open in Resource View tab then Right click on "Resources.rc" => Add Resource => Cursor => New (Here you can modify cursor appearance by pen)
Go back to solution explorer and now you will see resource.h file where you can find its id
#define IDC_CURSOR1 101
Build dll in Release mode
In Release sub folder you can find Resource.res
file
Now we have proper .res
file, We should add it to our UWP project root folder.
Copy Resource.res
file to UWP project root directory. (You can delete DLL project as it is no longer needed )
Unload UWP project in VS.
Rigth click on unloaded project and select edit .csproj
in first or second PropertyGroup (where is Appname, TargetPlatform, etc ) add
<PropertyGroup> ..... <Win32Resource>Resource.res</Win32Resource> </ PropertyGroup>
Reload project
Use following code for set cursor in your image PointerEnter event handler
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Custom, 101);
If you need to create a colorized *.cur file use any free tools like I did here. And just replace the source *.cur with a new one. And if you need a small *.cur file just remember that by default its size is 32 x 32 pixels and you have draw your small image like I did.
Enjoy!
Upvotes: 0
Reputation: 3808
You should create your own cursor *.res resource file and contains the custom cursor to your project by add it to your package.manifest file. After that, you can use CoreCursorType.Custom enumeration option, and specify the Id of the custom cursor to use the custom cursor. There also have a thread in which @Azat Tazayan has introduced the detailed steps to implement it and you can refer to it:
Upvotes: 1