WPF TextBlock Contents not read by screen reader
Asked Answered
L

3

3

I have an application that contains custom WPF Windows that are used to show a popup similar to the Win32 MessageBox.

As part of the requirements the application must be accessible through Screen Readers, and specifically JAWS. I have had problems getting the screen reader to read out the text in the dialog, but it will read the values in the buttons ok.

The code in the XAML is as follows

<Window x:Class="UserControls.ModalDialog"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:converters="clr-namespace:UserControls.Converters"
         mc:Ignorable="d" 
         d:DesignHeight="160" d:DesignWidth="400" MinHeight="85" MinWidth="400" MaxWidth="400" SizeToContent="Height" Height="Auto"
        WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Title="Popup Dialog">

<StackPanel Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
        <StackPanel.Resources>
            <converters:DisplayIconToSystemIconConverter x:Key="DisplayIconToSystemIconConverter"/>
        </StackPanel.Resources>
        <Image Source="{Binding IconType, Converter={StaticResource DisplayIconToSystemIconConverter}}" Height="32" Width="32" Margin="0,0,10,0"/>
        <TextBlock Name="TextBlock" Margin="20,10,0,0" TextWrapping="Wrap" Width="350" Foreground="DarkSlateGray" FontSize="10" FontWeight="Normal">
            <Run Text="Some text in the dialog"/>
        </TextBlock>
    </StackPanel>

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,5,0">
        <Button Name="Option1Button" Content="OK" Padding="5,0,5,0" Margin="0,20,5,0" MinWidth="100" IsDefault="True" />
        <Button Cancel Padding="5,0,5,0"  Margin="2,20,10,0" MinWidth="75" IsCancel="True" Visibility="Visible"/>
    </StackPanel>
</StackPanel></Window>

This code displays the popup correctly when called, but the screen reader only reads the title twice.

If I add an empty ListView control into the Window as the next element after the TextBlock, the screen reader correctly reads the dialog text, despite the two controls not being explicitly linked, but I cannot have an extra control like this in the control as it will affect the layout.

Is there a way to get the screen reader to correctly read the TextBlock text without having the list view in the control as well?

Larocca answered 19/8, 2014 at 12:35 Comment(0)
L
3

I was able to fix this by giving a value for the AutomationProperties.HelpText property on the Run of the TextBlock and focusing on the TextBlock once the window had loaded.

Larocca answered 26/8, 2014 at 13:42 Comment(2)
Does not look like run exposes HelpText Property ? msdn.microsoft.com/en-us/library/windows/apps/…Loquacious
'AutomationProperties.HelpText' is an attached property. It doesn't belong to the Run class. You set it in xaml by writing AutomationProperties.HelpText="<your text here>"; and in the code behind by calling AutomationProperties.SetHelpText(myRun, "your text here");Bach
P
3

It seems as though WPF still doesn't provide full support for all screen readers. I have searched online and initially only found unanswered similar questions:

WPF: how to make the Screen reader to read the text from a TextBox

After continuing, I found that there is one reader that does appear to work with WPF: NVDA. To find out more, please view the NVDA Community page. I found this from the following question:

Screenreader (NVDA) only reads WPF Window-Title

Furthermore, it seems as though you will need to set the x:Uid properties (normally reserved for the WPF UI automation) to the string to read out. I found this from the following question:

How-to for making my WPF app screen reader compatible?

Finally, you can find a useful tutorial for providing accessibility in WPF Applications in the How to Code WPF Applications for Accessibility on the Dev Pro website.

Perjury answered 19/8, 2014 at 13:2 Comment(1)
Hi Sheridan, thanks for the reply, Unfortunately the customer uses Jaws so changing the Screen reader being used is not an option. I have also tried setting automation properties on the text block without success, which I find unusual as elsewhere in the application, I have set automation properties on UIElements that have behaved correctly. I will keep plugging away at it.Larocca
L
3

I was able to fix this by giving a value for the AutomationProperties.HelpText property on the Run of the TextBlock and focusing on the TextBlock once the window had loaded.

Larocca answered 26/8, 2014 at 13:42 Comment(2)
Does not look like run exposes HelpText Property ? msdn.microsoft.com/en-us/library/windows/apps/…Loquacious
'AutomationProperties.HelpText' is an attached property. It doesn't belong to the Run class. You set it in xaml by writing AutomationProperties.HelpText="<your text here>"; and in the code behind by calling AutomationProperties.SetHelpText(myRun, "your text here");Bach
C
2

Setting Focusable to true on TextBlock worked for me

Culley answered 17/6, 2021 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.