2013-02-14 8 views
1

테이블 부모 내에 행 개체가있는 개체 트리가 있습니다. 나는 AutomationElementCollectionWindows.Automation을 사용하여 정규식으로 AutomationElement를 찾을 수 있습니까?

AutomationElementCollection asdf = ParentTableObj.FindAll 
    (
    TreeScope.Children, 
    new PropertyCondition 
      (
      AutomationElement.NameProperty, 
      "I want to use regex here" 
     ) 
    ); 

에 행 'AutomationElement.NameProperty의 모든 문자열 "행"을 포함을 모든 행을 넣어 시도하고있다. 그러나 그 문자열의 변형입니다 (예 : FindAll 방법을 사용하여 TreeScope을 정의하고 제공 Condition 매개 변수에 일치하는 AutomationElement을 찾을 수 있기 때문에 내가 뭔가를 누락 될 수 있습니다처럼 "ROW1", "행 2", "TopRow"...

보인다. 검색 범위를 이미 제어 할 수 있으므로 내 조건은 제한되지 않아야합니다. TreeScope.

답변

3
//Example : 
AutomationElement element = FindFirstDescendant( 
    AutomationElement.FromHandle(windows_hWnd), 
    (ele)=>Regex.IsMatch(ele.Current.Name, pattern) 
); 

//The generic method to find a descendant element: 
public static AutomationElement FindFirstDescendant(AutomationElement element, Func<AutomationElement, bool> condition) { 
    var walker = TreeWalker.ControlViewWalker; 
    element = walker.GetFirstChild(element); 
    while (element != null) { 
     if (condition(element)) 
      return element; 
     var subElement = FindFirstDescendant(element, condition); 
     if (subElement != null) 
      return subElement; 
     element = walker.GetNextSibling(element); 
    } 
    return null; 
} 
+0

FindDescendant가 정의되어 있지 않습니다. –

+0

@ 존 스미스 (John Smith), 답변을 업데이트했으며 이름이 FindFirstDescendant로 변경되었습니다. –

3

As the documentation states 대소 문자를 구분하지 않는 비교를 요청할 수 있습니다. "정규 표현식"플래그가 없습니다. 수동으로 필터링을 수행해야합니다.

+0

나는 이것이 사실일지도 모른다라고 생각했다 - 명확히 해 주어서 고맙다! – Zee