I want to use an image or icon as a custom cursor in WPF app. How can I do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have two basic options:
this.Cursor = Cursors.None;and draw your own cursor using whatever technique you like. Then, update the position and appearance of your cursor by responding to mouse events. Here are two examples:http://www.xamlog.com/2006/07/17/creating-a-custom-cursor/
http://www.hanselman.com/blog/DeveloperDesigner.aspx
Additional examples can be found here:
WPF Tutorial – How To Use Custom Cursors
Setting the Cursor to Render Some Text While Dragging
Getting fancy and using the Visual we are dragging for feedback [instead of a cursor]
How can I drag and drop items between data bound ItemsControls?
If you choose to load from a file, note that you need an absolute file-system path to use the
Cursor(string fileName)constructor. Lamely, a relative path or Pack URI will not work. If you need to load the cursor from a relative path or from a resource packed with your assembly, you will need to get a stream from the file and pass it in to theCursor(Stream cursorStream)constructor. Annoying but true.On the other hand, specifying a cursor as a relative path when loading it using a XAML attribute does work, a fact you could use to get your cursor loaded onto a hidden control and then copy the reference to use on another control. I haven’t tried it, but it should work.