1

テーブルの親内に行オブジェクトを持つオブジェクトツリーがあります。これらすべての行をに入れようとしていますAutomationElementCollection

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

すべての行AutomationElement.NamePropertyには、文字列「row」が含まれています。ただし、これらはその文字列のバリエーションです。たとえば、「Row1」、「Row2」、「TopRow」、...

このメソッドでは、提供されたパラメーターに一致するFindAllを定義しTreeScopeて検索できるため、何かが足りないようです。で検索スコープを制御できるので、条件を制限しないようにしたいだけです。AutomationElementConditionTreeScope

4

2 に答える 2

4
//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;
}
于 2013-10-16T18:18:06.613 に答える
3

As the documentation states, you can ask for a case-insensitive comparison. There is no "regular expression" flag. You will have to do the filtering manually.

于 2013-02-15T02:55:09.393 に答える