【问题标题】:WPF TextBlock Contents not read by screen reader屏幕阅读器未读取 WPF TextBlock 内容
【发布时间】:2014-08-19 12:35:27
【问题描述】:

我有一个包含自定义 WPF 窗口的应用程序,用于显示类似于 Win32 消息框的弹出窗口。

作为要求的一部分,应用程序必须可以通过屏幕阅读器访问,特别是 JAWS。我在让屏幕阅读器读取对话框中的文本时遇到问题,但它会读取按钮中的值。

XAML中的代码如下

<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>

此代码在调用时正确显示弹出窗口,但屏幕阅读器只会读取两次标题。

如果我在窗口中添加一个空的 ListView 控件作为 TextBlock 之后的下一个元素,屏幕阅读器会正确读取对话框文本,尽管这两个控件没有显式链接,但我不能在控制,因为它会影响布局。

有没有办法让屏幕阅读器在控件中也没有列表视图的情况下正确读取 TextBlock 文本?

【问题讨论】:

    标签: wpf xaml accessibility screen-readers


    【解决方案1】:

    似乎 WPF 仍然没有为所有屏幕阅读器提供完全支持。我在网上搜索过,最初只发现了没有答案的类似问题:

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

    继续之后,我发现有一个阅读器似乎可以使用 WPF:NVDA。要了解更多信息,请查看NVDA Community 页面。我从以下问题中找到了这一点:

    Screenreader (NVDA) only reads WPF Window-Title

    此外,您似乎需要将x:Uid 属性(通常为 WPF UI 自动化保留)设置为要读出的字符串。我从以下问题中找到了这一点:

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

    最后,您可以在 Dev Pro 网站上的 How to Code WPF Applications for Accessibility 中找到有用的教程,以在 WPF 应用程序中提供可访问性。

    【讨论】:

    • 您好 Sheridan,感谢您的回复,不幸的是,客户使用 Jaws,因此无法选择更改正在使用的屏幕阅读器。我还尝试在文本块上设置自动化属性但没有成功,我发现这在应用程序的其他地方很不寻常,我在 UIElements 上设置了行为正确的自动化属性。我会继续努力的。
    【解决方案2】:

    我可以通过为TextBlockRun 上的AutomationProperties.HelpText 属性赋值并在加载窗口后专注于TextBlock 来解决此问题。

    【讨论】:

    • 看起来不像 run 暴露了 HelpText 属性? msdn.microsoft.com/en-us/library/windows/apps/…
    • 'AutomationProperties.HelpText' 是附加属性。它不属于Run 类。您可以通过编写 AutomationProperties.HelpText="&lt;your text here&gt;" 在 xaml 中设置它;并在后面的代码中调用AutomationProperties.SetHelpText(myRun, "your text here");
    【解决方案3】:

    在 TextBlock 上将 Focusable 设置为 true 对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 2013-10-20
      • 2012-04-11
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 2022-08-23
      相关资源
      最近更新 更多