2013-07-09 17 views
7

Tôi có một ứng dụng WPF cần trình đọc màn hình hỗ trợ (đặc biệt là JAWS). Vấn đề là, JAWS không thông báo bất cứ điều gì, khi danh sách các mục đã thay đổi (thêm, xóa). Và người dùng mù hoàn toàn không biết chuyện gì đã xảy ra. Tôi có cách nào để buộc trình đọc màn hình thông báo một số văn bản, khi cố gắng thêm/xóa mục khỏi kiểm soát chế độ xem danh sách không? và làm thế nào tôi có thể làm điều đó?Làm cách nào để buộc trình đọc màn hình (JAWS) thông báo văn bản tùy chỉnh, khi các mục của chế độ xem danh sách (WPF) thay đổi?

+0

Bạn có thể thử tập trung mục mới. Thông thường người kể chuyện/công cụ trợ năng chỉ đọc những gì được tập trung. – AndrewS

Trả lời

3

Nếu trình đọc JAWS không hỗ trợ chức năng này, bạn có thể tự mình thực hiện theo SpeechSynthesizer. Ví dụ phát lại giọng nói:

using System.Speech.Synthesis; 

SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer(); 
MySpeechSynthesizer.Speak("Hello!"); 

tôi đã sử dụng các ví dụ về một ObservableCollection được gán ListBox. ObservableCollection là một sự kiện CollectionChanged, trong đó có chứa các liệt kê các hành vi thực hiện trên bộ sưu tập [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. 

event này sẽ được thực hiện như thế này:

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

Dưới đây là ví dụ của tôi:

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> 

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); 
    } 
} 

Nếu không có vấn đề, bạn có thể thêm văn bản sao chép của Add/Remove mục. Bạn cũng có thể thêm chơi .wav tập tin sử dụng PromptBuilder:

PromptBuilder MyPromptBuilder = new PromptBuilder(); 

MyPromptBuilder.AppendAudio("SomeFile.wav"); 
+0

Cảm ơn. nhưng tôi muốn JAWS công bố văn bản. –

3

JAWS sẽ chỉ trả lời điều khiển được tập trung. Tôi cần chức năng tương tự trong ứng dụng của tôi và giải quyết nó với những điều sau đây.

  1. Thêm hai điều khiển hộp văn bản ẩn vào bố cục của bạn.

    <!--Controls used to announce accessibility messages for screen readers.--> 
    <TextBox x:Name="ATMessage_Silent" Height="1" Width="1" IsTabStop="False" AutomationProperties.Name=" "/> 
    <TextBox x:Name="ATMessage_Audible" Height="1" Width="1" IsTabStop="False"/> 
    
  2. Thêm lớp để thông báo tin nhắn. Tôi thấy rằng để làm cho nó đáng tin cậy tôi cần phải tạm dừng một thời gian ngắn giữa việc chuyển tiêu điểm giữa nhiều điều khiển. Nếu không, JAWS sẽ không công bố tin nhắn một cách đáng tin cậy.

    public class AccessibilityMessage 
    { 
        private AccessibilityMessage(object sender, string message, double delay) 
        { 
         DispatcherTimer sleep = new DispatcherTimer(); 
         int counter = 3; 
    
         try 
         { 
          if (accessibilityMessageAudibleControl != null && accessibilityMessageSilentControl != null) 
          { 
           sleep.Interval = TimeSpan.FromMilliseconds(delay); 
    
           // Update the message. 
           accessibilityMessageAudibleControl.SetValue(AutomationProperties.NameProperty, message); 
    
           // Give focus to the silent control. 
           accessibilityMessageSilentControl.IsTabStop = true; 
           accessibilityMessageSilentControl.Focus(); 
    
           // Give focus to the message. 
           accessibilityMessageAudibleControl.IsTabStop = true; 
           accessibilityMessageAudibleControl.Focus(); 
    
           // Use a timer to simulate a sleep. We need to pause briefly to give enough time 
           // for the screen reader to process the focus on the message control. After a brief 
           // pause we will give focus back to the original control. If we do not pause like 
           // this the screen reader will not reliably react to the message. 
           sleep.Tick += (s, e) => 
           { 
            counter--; 
    
            // Check to see if it is time to focus the original control. 
            if (counter == 0) 
            { 
             // Return focus to the original control that triggered the message. 
             if (sender != null && sender is Control) 
             { 
              // Give focus back to the original control. 
              ((Control)sender).Focus(); 
             } 
    
             // Exit the timer. 
             sleep.Stop(); 
    
             // Inform any listeners the message has been announced. 
             if (Announced != null) 
              Announced(this, null); 
            } 
           }; 
    
           // Start the time. 
           sleep.Start(); 
          } 
          else 
          { 
           throw new Exception("Accessibility message controls are not defined in the Application Manager. Unable to announce accessibility message."); 
          } 
         } 
         catch (Exception ex) 
         { 
          ErrorDialog.Show(ex, sender); 
         } 
        } 
    
        public event EventHandler Announced; 
    
        public static AccessibilityMessage Announce(object sender, string message, double delay = 250) 
        { 
         return new AccessibilityMessage(sender, message, delay); 
        } 
    } 
    
  3. Thông báo thư của bạn. Bạn có thể chỉ cần thực hiện một thông báo hoặc sử dụng sự kiện được công bố, bạn có thể thực hiện thông báo và sau đó thực hiện công việc bổ sung sau khi thông báo được thực hiện.

    Thực hiện thông báo để thông báo cho người dùng vui lòng đợi trong khi lưới dữ liệu được tải dữ liệu.

    // Pass myGrid as the sender so it will receive focus after the announcement. 
    ApplicationManager.AccessibilityMessage.Announce(myGrid, "Loading purchase orders table, please wait.").Announced += (s, arg) => 
    { 
        // MAKE WEB SERVICE CALL TO RETRIEVE DATA. 
        DataService svc = new DataService(); 
        svc.ListPurchasOrdersCompleted += OnListPurchaseOrders_Completed(); 
        svc.ListPurchaseOrders(); 
    }; 
    

    Thông báo rằng dữ liệu đã được tải vào lưới dữ liệu.

    private void OnListPurchaseOrders_Completed(object sender, AsyncCompletedEventArgs e) 
    { 
        try 
        { 
         if (e.Error == null) 
         { 
          myGrid.ItemsSource = e.Result(); 
    
          // Pass myGrid as the sender so it will receive focus after the announcement. 
          AccessibilityMessage.Announce(myGrid, string.Format("Loaded {0} orders into the purchase orders table.", myGrid.Items.Count)); 
         } 
         else 
         { 
          throw e.Error; 
         } 
        } 
        catch (Exception ex) 
        { 
         ErrorDialog.Show(ex, this); 
        } 
    } 
    

Sử dụng này, bạn có thể làm cho thông báo bất cứ khi nào bạn muốn chỉ đơn giản bằng cách sử dụng các cuộc gọi Thông báo(). Ban đầu tôi đã thực hiện điều này cho Silverlight. Nó cũng làm việc cho WPF.

+0

Cảm ơn Eric, nó làm việc tốt cho tôi. –

Các vấn đề liên quan