2011-07-17 1 views
1

UIAutomation에 대한 작업을하고 WPF에서 AvalonEdit 컨트롤의 내용을 가져와야합니다.UIAutomation을 사용하여 AvalonEdit에서 텍스트 가져 오기

var targetTextPattern = editor[0].GetCurrentPattern(TextPattern.Pattern) as TextPattern; 

나는를 추출 할 수있는 방법을 찾을 수 없습니다 ...이 지원되지 않습니다

var editors = app.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)); 

: 나는 텍스트의 ControlType로 AvalonEdit 제어를 잡아에만 수 있어요 이 텍스트 콘텐츠는 ControlType.Text를 사용할 때 가능하지 않습니까? 나는 또한 ControlType 편집 & 문서를 사용하여 시도했지만 AvalonEdit이 그들을 지원하는 것 같지 않습니다.

도움이 필요하십니까? 감사합니다.

답변

2

소스 코드를 파고 들자면 AvalonEdit.TextEditor가 UIAutomation을 지원한다는 것을 알았습니다. 이것들은 그것을 사용하는 데 필요한 완전한 단계입니다. 이 같은 valuePattern이 사용하므로 UIAutomation를 사용하여 문서 편집기에서 텍스트를 얻기 위해,

allEditors = app.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 

TextEditorAutomationPeer 클래스는 IValueProvider를 구현 :

var editorValuePattern = allEditors[0].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; 
var text = editorValuePattern.Current.Value; 

이를

첫째, 문서 편집기를 찾기 위해 ControlType.Custom를 사용 나를 위해 일했다.