Search code examples
c#wpfaccessibilitynarrator

Wrong reading order in Narrator


I've got a problem with Microsoft Narrator.

I've got a WPF fragment like this:

<Window
    x:Class="InlineEditbox.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Narrator test" SizeToContent="WidthAndHeight">
    <TextBlock>
        <Run xml:space="preserve">I want to pay </Run>
        <InlineUIContainer>
            <TextBox Width="70" HorizontalContentAlignment="Right">0</TextBox>
        </InlineUIContainer>
        <Run xml:space="preserve"> % more</Run>
    </TextBlock>
</Window>

The text is displayed correctly; however the Narrator reads it this way: "I want to pay percent more, zero" instead of the expected "I want to pay 0 percent more".

Am I doing something wrong? The Narrator could have read the whole text just consequently. Is there a way to work around the problem without the need to change the actual text?


Solution

  • Answer from WPF team member:

    WPF supports a text control that can have child controls intermixed with its text. The UI Automation tree does not. There is no way describe to automation clients where the child edit control lives within the parent's text. WPF cannot easily fix this - it's a limitation of the automation architecture.

    To workaround, one can put the text into separate controls to describe the order in a way that translates to automation:

    <TextBlock>I want to pay</TextBlock>
    <TextBox> 0 </TextBox>
    <TextBlock>% more</TextBlock>
    

    Thx, Rob Relyea

    WPF Team