dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.08k stars 1.17k forks source link

WPF PasswordBox does not tab/Narrator read focus correctly in .NET Framework 4.6 #3227

Closed shcummin closed 4 years ago

shcummin commented 4 years ago

Narrator will not read PasswordBox - "foo" - unless the project is built with .NET 4.7+

Expected behavior:

Same behavior as .NET 4.8 - tabbing through the three items reads each automation name.

Minimal repro:

See above

rladuca commented 4 years ago

There was a change made for (I believe .NET 4.7.1) that fixes this. The target framework of the application determines the state of several accessibility feature AppContext flags that guard many of the accessibility fixes.

In this case, you need to ensure that Switch.UseLegacyAccessibilityFeatures is set to false in your application. If you are targeting 4.7.1+ you get this for free, but if your target framework is lower, you will need to set this manually. See this page for a rundown of these switches and their use.

It's worth noting that if you target 4.6 (setting the correct flags) you still won't see this behavior until you run on a machine where the installed framework version is 4.7.1+. If you're running on an installed version of 4.6, the code simply doesn't exist so there is nothing for the flag to enable.

rladuca commented 4 years ago

By the way, the line you're specifically interested in from the webpage is probably:

"In .NET Framework 4.7 and earlier versions, PasswordBox controls were announced as “no item in view” or had otherwise incorrect behavior. This issue is fixed starting with .NET Framework 4.7.1."

You can see the fixed code here.