I have a WPF application which prints 1 to 50 numbers and both XAML and code are given below. My requirement is to read out the label values with screen reader NVDA every time when a new content is set. My question is how to achieve readout the content which changes dynamically? Could you please help me to achieve this? Thanks
My XAML is
<Window x:Class="WPFAccessibility.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFAccessibility"
mc:Ignorable="d"
Title="WPFAccessibility" Height="450" Width="800">
<Grid>
<Label Name="progressLabel" FontSize="20" Margin="50,50"></Label>
</Grid>
</Window>
My code behind file is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace WPFAccessibility
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var mySource = Enumerable.Range(1, 50).ToList();
Task.Factory.StartNew(() => DoOperation(mySource));
}
private void DoOperation(List<int> values)
{
foreach (var i in values)
{
Thread.Sleep(1000);
var currentProgress = i;
Dispatcher.BeginInvoke(new Action(() =>
{
Process(currentProgress);
}), DispatcherPriority.Background);
}
}
private void Process(int currentProgress)
{
progressLabel.Content = "Processing... " + currentProgress;
if (currentProgress == 50)
progressLabel.Content = "Processing completed.";
}
}
}