C# RichTextBox的自动化支持-无法使用白色';隋

C# RichTextBox的自动化支持-无法使用白色';隋,c#,wpf,ui-automation,C#,Wpf,Ui Automation,我正在尝试使用从RichTextBox读取文本,但是它总是返回null 已将以下代码添加到RichtextBox.cs protected override AutomationPeer OnCreateAutomationPeer() { return new RichTextBoxAutomationPeer(this); } 有什么解决办法来获取文本吗?还是使用文本模式 我使用白色已经有一段时间了,我知道这已经很晚了,但我也遇到了同样的问题。我使用文

我正在尝试使用从RichTextBox读取文本,但是它总是返回null

已将以下代码添加到RichtextBox.cs

   protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new RichTextBoxAutomationPeer(this);
    }

有什么解决办法来获取文本吗?还是使用文本模式

我使用白色已经有一段时间了,我知道这已经很晚了,但我也遇到了同样的问题。我使用文本模式从富文本框中获取值,找到下面的示例代码,希望这对其他方面有所帮助

 AutomationElement ele =window.GetElement(SearchCriteria.ByAutomationId("richTextBoxId>"));

        if (ele != null)
        {
            TextPattern txtPattern = ele.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
            String controlText = txtPattern.DocumentRange.GetText(-1);
            Debug.WriteLine("the text is" + controlText);

        }