WPF: A screen reader isn't announcing an update to a status string or error string

This article is referenced directly by Microsoft Accessibility Insights for Windows. Microsoft Accessibility Insights for Windows can help spotlight many accessibility issues in UI, and guide you to the relevant UI framework-specific code sample to help you resolve the issue. Learn more about Microsoft Accessibility Insights for Windows.

Problem

My app UI can change to show an important update to status string or error string. A screen reader doesn't announce that string when the update occurs, and so my customers are not made aware of that important information which is now available.

Suggested Fix

If you can leverage functionality available in .NET 4.7.1, consider making the TextBlock associated with the status or error string, a LiveRegion. A LiveRegion is an area of your app's UI where updates to that area should be announced by a screen reader at the time the updates occur. The WPF property associated with LiveRegions is AutomationProperty.LiveSetting.

Code Sample 1: Setting the TextBlock to be a LiveRegion.

Important: This is for apps targeting .NET 4.7.1 or later.

<!-- In XAML -->

<!-- The Assertive property is used to request that the screen reader announces 
     the update immediately. An alternative setting of Polite requests that the 
	 screen reader completes any in-progress announcement before announcing the 
	 LiveRegion update. -->
<TextBlock x:Name="StatusBlock" AutomationProperties.LiveSetting="Assertive" ... />


// In code-behind.

// Important: In order for a screen reader to be made aware of the change to the 
// LiveRegion, a LiveRegionChanged event must be raised in code-behind. Always 
// raise the event after the updated text has been set on the TextBlock.
var peer = FrameworkElementAutomationPeer.FromElement(StatusBlock);
if (peer != null)
{
	peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
}