I have a TextBlock and I want to track that control from Screen reader and whenever a new value is set to the control in code, the screen reader should readout the new text. Thi
Use the CreatePeerForElement
method to create a UIElementAutomationPeer
for the TextBlock
:
private void Save_Click(object sender, RoutedEventArgs e)
{
MyTextBlock.Text = "My changed text";
var peer = UIElementAutomationPeer.FromElement(MyTextBlock);
if (peer == null)
peer = UIElementAutomationPeer.CreatePeerForElement(MyTextBlock);
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
}