【问题标题】:Screen reader not reading TextBlock content in WPF application屏幕阅读器未读取 WPF 应用程序中的 TextBlock 内容
【发布时间】:2022-03-24 02:40:11
【问题描述】:

我正在编写一个 WPF (.net 5) 应用程序,该应用程序应该支持可访问性,特别是 windows 叙述者以读出屏幕文本。我使用了很少的TextBlocks,并希望一旦显示窗口,叙述者就会开始一一阅读屏幕上的所有文本。

我观察到,当Button 的内容被读出时,任何TextBlock 的内容根本不会被叙述者阅读。

如何让旁白将窗口的所有内容一一读出。

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

【问题讨论】:

    标签: wpf windows accessibility narrator


    【解决方案1】:

    这是我使用的一种样式,它使每个文本块在讲述人打开时都可以聚焦,但在讲述人关闭时不会创建一堆额外的制表位。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 2022-08-23
      • 2018-07-19
      • 1970-01-01
      • 2011-04-09
      相关资源
      最近更新 更多