Search code examples
wpfaccessibilitysection508wcag2.0narrator

WPF: How to prevent reading underscore character of the AccessText element by Narrator?


I faced a strange issue when trying to support both keyboard and Narrator accessibility.

In the following XAML code:

<StackPanel>
    <CheckBox Name="CheckBox"
              AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text)}">
        <AccessText >C_heck me</AccessText>
    </CheckBox>
</StackPanel>

Default Windows 10 Narrator reads "C underscore heck me CheckBox unchecked".

Is there any way to keep keyboard navigation and to get readings from the Narrator as "Check me checkbox unchecked"?

Please note, the code above is an example and I have a lot of places where similar issues occur. I was already tried to add a converter and use it with AutomationProperties.Name but it caused an application slowness.


Solution

  • Your approach of using your own (say) AccessTextToAutomationPropertiesNameConverter() which strips the underscore, would be an attractive way to go for some apps. What was the performance impact in your app when you did that, (and how many controls were having to run through the converter)? Did your converter have a Mode of OneTime? Another option would be to have separate localized strings for the AutomationProperties.Name and the AccessText, but I can see how that's not attractive given that it'll increase the localization costs.