改变WPF,有时作品光标,有时不 [英] Changing the cursor in WPF sometimes works, sometimes doesn't
问题描述
在我的几个用户控件,我用改变光标
On several of my usercontrols, I change the cursor by using
this.Cursor = Cursors.Wait;
当我点击的东西。
when I click on something.
现在我想要做同样的事情在WPF页面上点击一个按钮。当我将鼠标悬停在我的按钮,光标变成一只手,但是当我点击它,它不会更改为等待光标。我不知道这事做的事实,这是一个按钮,或者因为这是一个网页,而不是一个用户控件?这似乎是不可思议的行为。
Now I want to do the same thing on a WPF page on a button click. When I hover over my button, the cursor changes to a hand, but when I click it, it doesn't change to the wait cursor. I wonder if this has something to do with the fact that it's a button, or because this is a page and not a usercontrol? This seems like weird behavior.
推荐答案
你需要光标是一个等待的光标,只有当它已经结束了对特定页面/用户控件?如果没有,我建议使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.overridecursor.aspx\">Mouse.OverrideCursor:
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.
这篇关于改变WPF,有时作品光标,有时不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!