Changing the cursor in WPF sometimes works, sometimes doesn't

后端 未结 5 623
[愿得一人]
[愿得一人] 2020-11-28 23:08

On several of my usercontrols, I change the cursor by using

this.Cursor = Cursors.Wait;

when I click on something.

Now I want to do

5条回答
  •  猫巷女王i
    2020-11-28 23:30

    If your application uses async stuff and you're fiddling with Mouse's cursor, you probably want to do it only in main UI thread. You can use app's Dispatcher thread for that:

    Application.Current.Dispatcher.Invoke(() =>
    {
        // The check is required to prevent cursor flickering
        if (Mouse.OverrideCursor != cursor)
            Mouse.OverrideCursor = cursor;
    });
    

提交回复
热议问题