我正在尝试使用White's UI automation framework 从RichTextBox读取文本,但它总是返回null。
已将以下代码添加到RichtextBox.cs
protected override AutomationPeer OnCreateAutomationPeer()
{
return new RichTextBoxAutomationPeer(this);
}
是否有任何解决方法来获取文本?或者使用TextPattern?
答案 0 :(得分:2)
我现在已经使用白色了一段时间,我知道这已经很晚了,但我遇到了同样的问题。我使用文本模式从富文本框中获取值,找到下面的示例代码,希望无论如何都有帮助。
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);
}