问题描述
我有一个包含自定义WPF Windows的应用程序,用于显示类似于Win32消息框的弹出窗口。
I have an application that contains custom WPF Windows that are used to show a popup similar to the Win32 MessageBox.
作为要求的一部分,必须可以访问该应用程序通过屏幕阅读器,尤其是JAWS。我在让屏幕阅读器读出对话框中的文本时遇到了问题,但是它将读取按钮中的值。
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.
XAML中的代码如下:
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.
如果我将一个空的ListView控件添加到Window中,作为TextBlock之后的下一个元素,则尽管两个控件未明确链接,但屏幕阅读器仍可正确读取对话框文本。我不能在控件中有这样的额外控件,因为它会影响布局。
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.
有没有一种方法可以使屏幕阅读器正确读取TextBlock文本而无需
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?
推荐答案
我能够通过提供<$ c $的值来解决此问题。 c> AutomationProperties.HelpText 属性,位于 TextBlock
的 Run
上,重点放在 TextBlock
窗口加载后。
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.
这篇关于屏幕阅读器无法读取WPF TextBlock内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!