wpf WPF中的默认光标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16189414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:40:13  来源:igfitidea点击:

Default cursor in WPF?

.netwpfcursor

提问by Brij

I am changing cursor of a control in WPF.

我正在更改WPF.

btn.Cursor = Cursors.Wait;

After carrying out an operaton, I want to revert back to the default cursor, I am did not find any Cursors.Default, how to get the default cursor ?

执行完一个操作后,我想恢复到默认光标,我没有找到任何Cursors.Default,如何获得默认光标?

回答by Eirik

You can override the cursor instead of setting the cursor, like this:

您可以覆盖光标而不是设置光标,如下所示:

Mouse.OverrideCursor = Cursors.Wait;

Then when the operation is carried out, you can remove the override by setting it to null, like this:

然后在执行操作时,可以通过将其设置为 null 来删除覆盖,如下所示:

Mouse.OverrideCursor = null;

回答by Kapitán Mlíko

You are right. There is no Cursors.Defaultstatic property. But you can always set cursor of a control to nulland it will restore control's default cursor.

你是对的。没有Cursors.Default静态属性。但是您始终null可以将控件的光标设置为,它会恢复控件的默认光标。

// ...
btn.Cursor = Cursors.Wait;
// whatever... your operation.
btn.Cursor = null;
// now the Cursor is default again.

回答by TheRedMonk

I think you need to store the current cursor in a variable before changing it to the Wait cursor and then set it to your cursor variable when you want to change it back.

我认为您需要在将当前游标更改为等待游标之前将其存储在一个变量中,然后在您想将其更改回来时将其设置为您的游标变量。