Of all the cur­sors that we come across on a daily basis, the grab image and grab­bing image cur­sors are two notable absen­tees in the list of sup­ported cur­sors in WPF/Silverlight.

So if you hap­pen to need these two cur­sors as I did ear­lier in the day, then here’s a few easy steps to get you going:

1. Down­load the grab.cur and grabbing.cur files from here and here.

2. Include them in your project, under a Resources/Cursors folder, like this:

image

3. Make sure the Build Action for both is set to ‘Resource’ (which is sim­i­lar to Embed­ded Resource, except Resource is intended for WPF/Silverlight and Embed­ded Resource is intended for older technologies):

image

4. You won’t be able to put them in as Resources directly, but you can put a ref­er­ence to them using dummy TextBlock controls:

<UserControl.Resources>
    <ResourceDictionary>
        <TextBlock x:Key="CursorGrab" Cursor="Resources/Cursors/grab.cur"/>
        <TextBlock x:Key="CursorGrabbing" Cursor="Resources/Cursors/grabbing.cur"/>
    </ResourceDictionary>
</UserControl.Resources>

5. Now you can retrieve the ref­er­ences to these cur­sors in code like this:

_grabCursor = ((TextBlock) Resources["CursorGrab"]).Cursor;
_grabbingCursor = ((TextBlock) Resources["CursorGrabbing"]).Cursor;
Share

3 Responses to “WPF — loading grab and grabbing cursors from resource”

  1. Alexander says:

    Super! No con­ver­sa­tion and no win32 wrap­per. very nice.
    thanx

  2. Paul Jackson says:

    Great post, and thanks for the cur­sor resources.
    Is there any par­tic­u­lar rea­son that you chose to use a TextBlock over FrameworkElement–where the Cur­sor prop­erty is first defined–to cache the cur­sor references?

    PJ

  3. Many thanks for the post and the .cur files

Leave a Reply