当列表视图(WPF)的项目发生变化时,如何强制屏幕阅读器(JAWS)宣布自定义文本?

Ale*_*ube 7 wpf screen-readers jaws-screen-reader

我有一个WPF应用程序需要支持屏幕阅读器(尤其是JAWS).问题是,当列表视图项已更改(添加,删除)时,JAWS不会发布任何内容.盲人用户完全不知道发生了什么.我有什么方法强制屏幕阅读器宣布一些文本,当尝试从列表视图控件添加/删除项目?我该怎么办?

Ana*_*aev 3

如果JAWS读者不支持该功能,可以通过 自行实现SpeechSynthesizer。语音播放示例:

using System.Speech.Synthesis;

SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();
MySpeechSynthesizer.Speak("Hello!");
Run Code Online (Sandbox Code Playgroud)

ObservableCollection我使用了分配的a 的示例ListBoxObservableCollection是一个事件CollectionChanged,其中包含对集合执行的操作的枚举[MSDN]

Member name   Description
------------  ------------
Add           One or more items were added to the collection.
Move          One or more items were moved within the collection.
Remove        One or more items were removed from the collection.
Replace       One or more items were replaced in the collection.
Reset         The content of the collection changed dramatically.
Run Code Online (Sandbox Code Playgroud)

event将像这样实现:

// Set the ItemsSource
SampleListBox.ItemsSource = SomeListBoxCollection;

// Set handler on the collection
SomeListBoxCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(SomeListBoxCollection_CollectionChanged);

private void SomeListBoxCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Add)
    {
        // Some actions, in our case - speech
    }
}
Run Code Online (Sandbox Code Playgroud)

下面是我的例子:

XAML

<Window x:Class="JAWShelp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    WindowStartupLocation="CenterScreen">

    <Grid>
        <ListBox Name="MyListBox" DisplayMemberPath="Name" SelectedIndex="0" Width="100" Height="100" Loaded="MyListBox_Loaded" />

        <WrapPanel Width="200" Height="30" Margin="40,150,0,0">
            <Button Name="AddButton" Padding="5" Content="Add item" VerticalAlignment="Bottom" Click="AddButton_Click" />
            <Button Name="RemoveButton" Padding="5" Margin="30,0,0,0" Content="Remove item" VerticalAlignment="Bottom" Click="RemoveButton_Click" />
        </WrapPanel>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

Code behind

// using System.Speech.Synthesis;
// using System.Collections.ObjectModel;
// using System.Collections.Specialized;

public partial class MainWindow : Window
{
    public class Person
    {
        public string Name
        {
            get;
            set;
        }
    }

    private ObservableCollection<Person> DataForListBox = new ObservableCollection<Person>();

    public MainWindow()
    {
        InitializeComponent();
    }

    private void MyListBox_Loaded(object sender, RoutedEventArgs e)
    {
        DataForListBox.Add(new Person()
        {
            Name = "Peter Orange",                
        });

        MyListBox.ItemsSource = DataForListBox;

        DataForListBox.CollectionChanged += new NotifyCollectionChangedEventHandler(DataForListBox_CollectionChanged);
    }

    private void DataForListBox_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();

            MySpeechSynthesizer.Speak("You are add item.");
        }

        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();

            MySpeechSynthesizer.Speak("You are remove item.");
        }
    }

    private void AddButton_Click(object sender, RoutedEventArgs e)
    {
        DataForListBox.Add(new Person()
        {
            Name = "Jack Rider",
        });
    }

    private void RemoveButton_Click(object sender, RoutedEventArgs e)
    {
        DataForListBox.RemoveAt(1);
    }
}
Run Code Online (Sandbox Code Playgroud)

没有问题,您可以添加项目的复制文本Add/Remove。您还可以.wav使用以下命令添加播放文件PromptBuilder

PromptBuilder MyPromptBuilder = new PromptBuilder();

MyPromptBuilder.AppendAudio("SomeFile.wav");
Run Code Online (Sandbox Code Playgroud)