我正在尝试使用 White's UI automation framework 从 RichTextBox 中读取文本但是它总是返回 null。
已将以下代码添加到 RichtextBox.cs
protected override AutomationPeer OnCreateAutomationPeer()
{
return new RichTextBoxAutomationPeer(this);
}
是否有任何解决方法来获取文本?或者使用 TextPattern?
最佳答案
我已经使用白色一段时间了,我知道这真的很晚了,但我遇到了同样的问题。我已经使用文本模式从富文本框中获取值,找到下面的示例代码,希望对您有所帮助。
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);
}
关于c# - RichTextBox 的自动化支持 - 无法使用 White'sUI 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27099058/