Click here to Skip to main content
11,716,938 members (86,992 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF VB.NET
Hi,

In one of the WPF application, I am setting cursor to Wait cursor with below code

Mouse.OverrideCursor = Windows.Input.Cursor.Wait

after some time I want to set it to default cursor.

Though in MSDN cursor class (System.Windows.Input.Cursor) default property is mentioned

I am not able to use it.

Is there any way to set the default cursor like we set in the form using Windows.Forms.Cursors.Default.




Appreciate the answer.

Vijay
Posted 19-Nov-12 14:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can do this:
System.Windows.Input.Cursor saveCursor = someFrameworkElement.Cursor;
someFrameworkElement.Cursor = Cursors.WaitCursor;
and, at the end
someFrameworkElement.Cursor = saveCursor;

Please also see my article where I show how to use using statement based in System.IDisposable to do such things:
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[^].

If works for both System.Windows.Forms and WPF.

Also, see more generic alternative to my solution, which I gladly accepted: Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[^].

Is is based on the RAII pattern: http://en.wikipedia.org/wiki/RAII[^].

This is something which is very good to know.

Good luck,
—SA
  Permalink  
v3
Comments
Vijay hit at 19-Nov-12 21:52pm
   
Hi Sergey,

Thanks for the answer.

Cursor.Current = Cursors.Default din't worked as Default is not appearing in cusors.
I am getting error like default is not a member of cursors.


But your blog helped a lot. I just used your technique of setting Previous and it worked well.

Dim previous as system.windows.input.cursor = me.cursor
me.Cursor = cursors.wait

after my task I reset the cursor by
me.cursor = previous.

Thanks again,
Vijay
Sergey Alexandrovich Kryukov at 19-Nov-12 23:37pm
   
Great.
Sorry, I messed up a bit, edited the sample; thank you for fixing it.
You are very welcome.
Good luck, call again.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You might use an extension method in a public static class

public static void UseWaitCursor(this FrameworkElement fel)
        {
            Mouse.OverrideCursor=Cursors.Wait;
            fel.Dispatcher.InvokeAsync(() => { Mouse.OverrideCursor=null; }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
        }

Then its easy like:

private void MainWindowLoaded(object sender, RoutedEventArgs e)
   {
     UseWaitCursor();
   ....
   }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 719
1 F-ES Sitecore 235
2 Maciej Los 185
3 OriginalGriff 175
4 Richard MacCutchan 130
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 4 Jun 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100