如何防止点击后WPF按钮保持突出显示? [英] How do I prevent WPF buttons from remaining highlighted after being clicked?

查看:220
本文介绍了如何防止点击后WPF按钮保持突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个标准的WPF按钮被点击时,它会以蓝色突出显示(可能使用来自任何Windows主题设置的蓝色),并保持突出显示,直到与其他任何控件交互。对于我的应用程序来说,这对用户来说是令人困惑的。



是否有一种简单的方法可以关闭此按钮并将按钮恢复为正常样式?
我正在使用.NET 4.

解决方案

会发生什么事,按钮接受输入焦点被点击后,就像任何其他控件一样,当你点击它。



而Windows的方式表明一个控件有输入焦点至少在Aero主题下)是一个微妙的蓝色突出显示。



对于一个按钮控制,当它具有输入焦点时,只需按下 Enter 键会推那个按钮。这就是为什么保持高亮显示非常重要,以便用户知道该期待什么。



更好的解决方案是在您的窗口中立即将焦点设置为不同的控件用户点击了按钮。这样,当用户按下 Enter 键时,将不会自动突出显示,也不会自动触发操作。 (这是你正在尝试解决的真正的可用性问题,即使你还不知道这个问题。没有什么比当用户实际尝试键入时无意中点击的按钮更混乱)



您可以通过设置 Focusable 属性为false,但是我会非常建议反对这一点。一旦你这样做了,用户将无法只使用键盘按下按钮。精心设计的应用程序应始终可供不喜欢或无法使用鼠标的用户访问。


When a standard WPF button is clicked, it gets highlighted in blue (probably using the blue color from whatever Windows theme is set), and it stays highlighted until you interact with any other control. For my application, it is confusing for the user.

Is there a simple way turn this off and get the button back to its normal style? I am using .NET 4.

解决方案

What happens is that the button accepts the input focus after it has been clicked, just like any other control does when you click on it.

And the way that Windows indicates that a control has the input focus (at least under the Aero theme) is with a subtle blue highlight.

For a button control in particular, when it has the input focus, simply pressing the Enter key will "push" that button. That's why maintaining the highlight is very important, so that the user knows what to expect.

The better solution is to set the focus to a different control in your window immediately after the user has clicked on the button. That way, it will no longer be automatically highlighted and no action will be automatically triggered when the user presses the Enter key. (This is the real usability problem that you're trying to solve, even if you don't know it yet. Nothing is more confusing than a button inadvertently getting clicked when the user is actually trying to type something.)

You could prevent the button from ever getting the focus altogether by setting its Focusable property to false, but I would very much recommend against this. Once you've done this, there will be no way for the user to "press" the button using only the keyboard. Well-designed applications should always be accessible to users who either prefer not to or who are unable to use the mouse.

这篇关于如何防止点击后WPF按钮保持突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆