3

I am writing a WPF (.net 5) application which should support accessibility specifically windows narrator to read out the screen text. I am using few TextBlocks and expect that as soon as window is shown narrator will start reading all the text present in the screen one by one.

What I observe is that while the Button's content are read out, any TextBlock content is not read by narrator at all.

How can I make the narrator to read all the content of the window one by one.

<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SampleApp"
        mc:Ignorable="d"
        TabIndex="0"
        Focusable="True"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBlock x:Name="firstText"
                       Text="This is the first line"
                       KeyboardNavigation.TabIndex="1"
                       KeyboardNavigation.TabNavigation="Continue"
                       AutomationProperties.AutomationId="firstTextBox"
                       AutomationProperties.Name="This is the first line"
                       />
            <TextBlock x:Name="secondText"
                       Text="This is the second line"
                       KeyboardNavigation.TabIndex="2"
                       KeyboardNavigation.TabNavigation="Continue"
                       AutomationProperties.AutomationId="secondTextBox"
                       AutomationProperties.Name="This is the second line"
                       />
        </StackPanel>

    </Grid>
</Window>
1
  • by what I've found till now - narrator is not reading TextBlock, so you'll have to redesign some button to look like the TextBlock in order to work around it. Commented Jun 28, 2024 at 10:39

1 Answer 1

0

Here is a style I use that makes each textblock focusable when the Narrator is on, but does not create a bunch of extra tabs stops if Narrator is off.

    <!-- WCAG variant -->
    <Style x:Key="WCAG_TextboxStyle" TargetType="{x:Type TextBlock}" 
           BasedOn="{StaticResource {x:Type TextBlock}}" >
    <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
    <Setter Property="Focusable" Value="False"/>
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsNarratorOn}" Value="true">
          <Setter Property="KeyboardNavigation.IsTabStop" Value="True"/>
          <Setter Property="Focusable" Value="True"/>
        </DataTrigger>
     </Style.Triggers>
    </Style>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.