Click here to Skip to main content
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 15: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 380
1 OriginalGriff 250
2 DamithSL 210
3 Kornfeld Eliyahu Peter 200
4 Peter Leow 95
0 OriginalGriff 7,315
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,917
3 Maciej Los 4,866
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 4 Jun 2014
Copyright © CodeProject, 1999-2014
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