【问题标题】:How to get Narrator to read the text in a WPF Popup?如何让讲述人阅读 WPF 弹出窗口中的文本?
【发布时间】:2021-09-21 21:51:54
【问题描述】:

我有一个包含按钮的 WPF 应用程序。当您按下按钮时,会打开一个PopupPopup 包含有关会议的信息。

打开讲述人后,Popup 的内容不会被读取。如何让讲述人阅读Popup 的内容?

这是Popup 的内容示例:

<Popup x:Class="ClassApp.UserInterface.Views.Windows.Settings.MeetingDetailsPopup"
             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:languages="clr-namespace:MyApp.UserInterface.CommonUI.Languages"
             xmlns:converters="clr-namespace:MyApp.Converters"
             xmlns:global="clr-namespace:"
             Height="375"
             mc:Ignorable="d"
             MaxHeight="375"
             MaxWidth="500" 
             StaysOpen="True"
             Placement="MousePoint" 
             Width="500">
    <Border BorderBrush="{StaticResource GrayBrush}"
            Background="{StaticResource TabSelectedBackgroundBrush}"
            BorderThickness="1">
        <Grid Margin="10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="25"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="35" />
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="Auto"
                               MinHeight="100"/>
                <RowDefinition Height="Auto"
                               MinHeight="40"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid Grid.Column="0"
                  Grid.ColumnSpan="3"
                  Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0"
                           AutomationProperties.AutomationId="ClassName"
                           AutomationProperties.Name="{Binding ClassName}"
                           FontSize="18"
                           FontWeight="Bold"
                           x:Name="ClassName"
                           Style="{StaticResource ClassInformationTextBlockStyle}"
                           Text="{Binding ClassName}"
                           TextWrapping="Wrap"
                           VerticalAlignment="Top"/>
                <Button Grid.Column="1" 
                        AutomationProperties.Name="{x:Static languages:Resources.Accessibility_CloseWindow}"
                        AutomationProperties.AutomationId="CloseWindow"
                        Command="{Binding CloseMeetingInfoCommand}"
                        Content="X"
                        FontSize="16"
                        HorizontalAlignment="Right"
                        x:Name="CloseButton"
                        Style="{StaticResource ClassInformationCloseButtonStyle}"
                        VerticalAlignment="Top"/>
            </Grid>
            <TextBlock Grid.Column="0"
                       Grid.Row="1"
                       AutomationProperties.Name="{x:Static languages:Resources.Label_MeetingID}"
                       FontSize="14"
                       Foreground="{StaticResource GrayBrush}"
                       x:Name="MeetingIdLabel"
                       Style="{StaticResource ClassInformationTextBlockStyle}"
                       Text="{x:Static languages:Resources.Label_MeetingID}"
                       VerticalAlignment="Top"/>
            <TextBlock Grid.Column="2"
                       Grid.Row="1"
                       AutomationProperties.AutomationId="MeetingId"
                       AutomationProperties.Name="{Binding MeetingID}"
                       AutomationProperties.LabeledBy="{Binding ElementName=MeetingIdLabel}"
                       FontSize="14"
                       Style="{StaticResource ClassInformationTextBlockStyle}"
                       Text="{Binding MeetingID}"
                       VerticalAlignment="Top"/>

                . . .
            </Grid>
        </Grid>
    </Border>
</Popup>

编辑:Popup 的其余部分包含更多 TextBlocks 和几个用于将链接或所有数据复制到剪贴板的按钮。我没有包括它,因为我认为它不重要。

【问题讨论】:

    标签: wpf accessibility narrator


    【解决方案1】:

    您需要将 Popup.IsKeyboardFocused 设置为 true。默认值为 false。

    这会将标签焦点移动到弹出窗口。请记住,当用户关闭它时,您需要将焦点移回(最好是打开弹出窗口的触发器)。

    【讨论】:

    • 谢谢!所以我在后面的代码中设置了这个,对吧?
    • OK 我刚才试了一下,发现Popup.IsKeyboardFocused没有setter。但是,我在Popup 上拨打了Focus() 并做到了。我在弹出窗口的后端添加了一个私有字段,以记住 IInputElementPopup 之前有焦点。这一切都很好。唯一的问题是屏幕阅读器没有阅读对话框中的文本。这一切都在TextBlock 控件中。我将尝试使用只读TextBoxes 来读取要阅读的文本。
    • 我通过将 TextBlock 控件更改为 Label 控件并为使用 Label 显示的 Label 控件创建 Style 来解决讲述人无法读取 TextBlock 控件的问题内容。
    猜你喜欢
    • 2019-01-08
    • 2011-03-13
    • 2011-10-29
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2012-07-15
    相关资源
    最近更新 更多