Skip to main content

Cursors.Wait in WPF?

In WinForms, setting the cursor to Cursors.Wait, and back to Cursors.Default would allow for an hour glass like effect to notify the user that the application is busy.

To achieve this with WPF in a quick and dirty way, you can simply override the mouse cursor.

1
2
3
    Mouse.OverrideCursor = Cursors.Wait;
    //code here
    Mouse.OverrideCursor = null;

Notice, we are setting the cursor to null at the end. This is going to achieve the same thing as Cursors.Default, but the reason we don't use that is because it is using System.Windows.Input.Cursors and not System.Windows.Forms.Cursors and thus there is no .Default. Setting to null results in the cursor going to default... by default.

Comments

Popular posts from this blog

Connecting VS 2008 to TFS?

Trouble connecting vs 2008 to TFS? If you are running a newer version of TFS, 2008 does not understand collections. In order to fix that, you need the following installed: SP1 http://www.microsoft.com/en-us/download/details.aspx?id=13276 Team Explorer http://www.microsoft.com/en-us/download/details.aspx?id=16338 Forwards Compatibility https://www.microsoft.com/en-us/download/details.aspx?id=10834

File menu opening on wrong side? [Windows 10]

If you are using windows 10 and the file menu opens on the left side, here is a fix: Run (Win+R) paste the following: shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} click "Other" tab choose "Left-handed" Now the menu should open within the window:

Updating UI during long operation

If you are performing an extensive operation that has multiple UI updates, for example in a loop, then you can use the following code to keep the UI updated alongside the operation. 1 2 3 4 5 6 7 8 9 10 private void UpdateUI() { DispatcherFrame update = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback( delegate ( object parameter) { update.Continue = false ; return null ; }), null ); Dispatcher.PushFrame(update); } Simply call that function inside your loop and the UI will update. Note, I have set the priority to background, you may have to set that to "Render"