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?
Trả lời
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");
Cảm ơn. nhưng tôi muốn JAWS công bố văn bản. –
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.
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"/>
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); } }
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.
Cảm ơn Eric, nó làm việc tốt cho tôi. –
- 1. Chế độ xem thông báo tùy chỉnh
- 2. Khi cuộn Chế độ xem danh sách tùy chỉnh, giá trị hộp kiểm thay đổi
- 3. Chế độ xem danh sách WPF: Căn chỉnh văn bản trong các cột được chọn
- 4. Quản trị Django - Chế độ xem thay đổi tùy chỉnh
- 5. Mục danh sách lặp lại trong chế độ xem danh sách tùy chỉnh android
- 6. Hoạt ảnh khi thay đổi chế độ xem văn bản
- 7. WPF TextBlock văn bản thay đổi thông báo
- 8. Làm cách nào để làm mờ chế độ xem mặt sau khi Chế độ xem tùy chỉnh được hiển thị
- 9. Làm cách nào để thay đổi màu văn bản của danh mục tùy chọn trong Android?
- 10. Android: Thay đổi hình ảnh cho một mục cụ thể trong chế độ xem danh sách
- 11. Làm cách nào để tắt các mục trong Chế độ xem danh sách?
- 12. Thay đổi chiều cao của chế độ xem đầu vào tùy chỉnh khi thiết bị xoay
- 13. Làm cách nào để buộc vẽ lại danh sách xem?
- 14. Làm cách nào để thay đổi kiểu tiết lộ khi người dùng vào chế độ chỉnh sửa của UITableView?
- 15. Tôi làm cách nào để tùy chỉnh chế độ xem cảnh báo trên iOS?
- 16. Nhiều lựa chọn trong Chế độ xem danh sách tùy chỉnh với CAB
- 17. Bắt đầu tạo chuyển đổi chế độ xem tùy chỉnh
- 18. Làm cách nào để vẽ văn bản trong chế độ xem tùy chỉnh bằng cách sử dụng Objective-C?
- 19. Có cách nào để có được các hành động quản trị Django tùy chỉnh xuất hiện trên chế độ xem "thay đổi" ngoài chế độ xem "danh sách thay đổi" không?
- 20. cách hiển thị chế độ xem danh sách tùy chỉnh sử dụng các phân đoạn danh sách trong android
- 21. ActionBarSherlock (ABS): cách tùy chỉnh văn bản của mục đóng chế độ hành động?
- 22. Làm cách nào để nhóm các mục danh sách HTML trong chế độ xem ASP.NET MVC?
- 23. Chế độ xem danh sách tùy chỉnh với hai nút trong mỗi hàng
- 24. Chế độ xem ảnh tùy chỉnh
- 25. Làm cách nào để buộc hướng màn hình trong các bộ điều khiển chế độ xem cụ thể?
- 26. Bàn điều khiển văn bản để phát triển trong JAWS?
- 27. Cách đưa vào chế độ xem danh sách xem danh sách được thêm gần đây trong Danh sách WPF
- 28. Làm thế nào để tùy chỉnh màn hình của dired
- 29. cách thêm chế độ xem chú dẫn tùy chỉnh trong chế độ xem bản đồ
- 30. Cách tải chế độ xem cho một mục trong chế độ xem danh sách trong Android?
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