我正在用UIAutomation做一些工作,需要在WPF中获得AvalonEdit控件的内容。我只能获得文本的ControlType形式的AvalonEdit控件:
var editors = app.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));这不受支持...
var targetTextPattern = editor[0].GetCurrentPattern( TextPattern.Pattern) as TextPattern;我似乎找不到一种方法来从这里提取文本内容,是不是在使用ControlType.Text时不能这样做?我也尝试过使用ControlType编辑和文档,但AvalonEdit似乎不支持它们。
任何帮助都是优先的。谢谢!
发布于 2011-07-19 04:27:29
在深入研究了源代码之后,我发现AvalonEdit.TextEditor确实支持UIAutomation。这些是使用它所需的完整步骤。
首先,使用ControlType.Custom查找TextEditor:
allEditors = app.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));TextEditorAutomationPeer类实现了IValueProvider,因此要使用UIAutomation从TextEditor获取文本,请使用如下所示的ValuePattern:
var editorValuePattern = allEditors[0].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
var text = editorValuePattern.Current.Value;这对我很有效:)
https://stackoverflow.com/questions/6722614
复制相似问题