Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent WPF buttons from remaining highlighted after being clicked?

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.

like image 781
learner Avatar asked May 10 '11 12:05

learner


3 Answers

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.

like image 130
Cody Gray Avatar answered Oct 15 '22 02:10

Cody Gray


Try to set Focusable to false. The button will be clickable but will not remain focused.

like image 21
HCL Avatar answered Oct 15 '22 01:10

HCL


That is simply the focussed state. To turn it off you will have to change the focussed state. It's easiest by using Blend.

I do not recommend setting Focusable to false because it interferes with using the keyboard

like image 2
Emond Avatar answered Oct 15 '22 03:10

Emond