3

I'm trying to load a local image and use it for the cursor. In order to do so I have to send a stream from the image to the Cursor(Stream cursorStream) constructor.

    var res = Application.GetResourceStream(new Uri("pack://application:,,,/MyProj;component/Images/delete-icon.png"));

    this.Cursor = new Cursor(res.Stream);

The problem is that I always get this exception

ReadTimeout = (res.Stream).ReadTimeout threw an exception of type 'System.InvalidOperationException'
WriteTimeout = (res.Stream).WriteTimeout threw an exception of type 'System.InvalidOperationException'

How should I do it?

alexa
  • 41
  • 1
  • 3
  • 1
    possible duplicate to: http://stackoverflow.com/questions/46805/custom-cursor-in-wpf – Kamil Lach Mar 02 '12 at 09:25
  • 1
    Full working example ca be found here: http://stackoverflow.com/questions/2835502/rotating-cursor-according-to-rotated-textbox/2836904#2836904 – Kamil Lach Mar 02 '12 at 09:26

1 Answers1

3

Cursor expects .cur file type. Also make sure the file in resource folder has its build action set to resource

Example: if following folder inside my project has .cur cursor file --> component/Resource/Images/BusyCursor.cur

I use below code and cursor changes for this control.

StreamResourceInfo sri = System.Windows.Application.GetResourceStream(
    new Uri("/<projectname>;component/Resource/Images/BusyCursor.cur", UriKind.RelativeOrAbsolute));

this.Cursor = new Cursor(sri.Stream);
aloisdg
  • 22,270
  • 6
  • 85
  • 105
Ira
  • 734
  • 10
  • 7