AutomationProperties.LiveSetting not working in WPF in .NET Framework 4.7.1

前端 未结 1 1577
深忆病人
深忆病人 2021-01-21 07:19

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

相关标签:
1条回答
  • 2021-01-21 07:46

    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);
    }
    
    0 讨论(0)
提交回复
热议问题