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

后端 未结 5 617
[愿得一人]
[愿得一人] 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条回答
  •  [愿得一人]
    2020-11-28 23:45

    Do you need the cursor to be a "wait" cursor only when it's over that particular page/usercontrol? If not, I'd suggest using Mouse.OverrideCursor:

    Mouse.OverrideCursor = Cursors.Wait;
    try
    {
        // do stuff
    }
    finally
    {
        Mouse.OverrideCursor = null;
    }
    

    This overrides the cursor for your application rather than just for a part of its UI, so the problem you're describing goes away.

提交回复
热议问题