sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Focus a disabled item

16 Jul 2021, 18:15

Hello,
A UX request came up to focus a disabled button. Activating the button shouldn't do anything, but we'd still like to show the focusing highlight on it?
Is there a way currently to do that nicely?
- There's a way to fake it with a disabled-looking button that does nothing and swap buttons to the real enabled one (This is is how we're doing it now).
- There's a way to make it work via a new button style that has different visual states and we just never set it to disabled.
.. I'm wondering if there's a more native way to approach it? Similar to "focusWithoutEnage", maybe "allowFocusWhenDisabled" or the like?
Cheers.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Focus a disabled item

19 Jul 2021, 13:10

When a control is disabled (its IsEnabled property is set to false) the user cannot give the control keyboard focus by clicking on it or by use of the tab key.
Disabled controls cannot get focus, even if both their Focusable and IsTabStop properties are set to true.

And unfortunately there is no property or state that represent such scenario.

But you can define custom visual states for your button control, and use attached properties to show that particular scenario. For example I just created this xamltoy to show a workaround:



Hope this helps.
 
sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Re: Focus a disabled item

19 Jul 2021, 21:37

Phenomenal, thank you!

Who is online

Users browsing this forum: Google [Bot] and 70 guests