问题描述
我有了一个父表中的行对象的对象树。我试图把所有这些行到 AutomationElementCollection
AutomationElementCollection航空自卫队= ParentTableObj.FindAll
(
TreeScope.Children,
新PropertyCondition
(
AutomationElement.NameProperty,
:我想在这里使用正则表达式
)
);
所有行'的 AutomationElement.NameProperty
包含字符串行。然而,他们是该字符串的变化 - 例如, ROW1,的Row2,TopRow,...
好像我可能会丢失,因为的FindAll $的东西C $ C>方法允许你定义
参数。我只是想不受限制我的病情,因为我已经可以控制由 TreeScope
并找到任何 AutomationElement
,它提供的<$ C $匹配C>条件 TreeScope
查找范围。
//例:
AutomationElement元= FindFirstDescendant(
AutomationElement.FromHandle(windows_hWnd),
(ELE)=> Regex.IsMatch(ele.Current.Name,图案)
);
//通用的方法找到一个后代元素:
公共静态AutomationElement FindFirstDescendant(AutomationElement元素,Func键< AutomationElement,布尔>条件){
VAR沃克= TreeWalker.ControlViewWalker ;
元素= walker.GetFirstChild(元);
,而(元素!= NULL){
如果(条件(元素))
返回元素;
无功子元素= FindFirstDescendant(元素,条件);
如果(子元素!= NULL)
返回子元素;
元素= walker.GetNextSibling(元);
}
返回NULL;
}
I have an object tree that has row objects within a table parent. I'm attempting to put all these rows into an AutomationElementCollection
AutomationElementCollection asdf = ParentTableObj.FindAll
(
TreeScope.Children,
new PropertyCondition
(
AutomationElement.NameProperty,
"I want to use regex here"
)
);
All of the rows' AutomationElement.NameProperty
contains the string "row". However, they are variations of that string - e.g. "Row1", "Row2", "TopRow", ...
It seems like I may be missing something since the FindAll
method allows you to define the TreeScope
and find any AutomationElement
, which matches the provided Condition
parameter. I just want my condition to be unrestricted since I can already control the find scope by TreeScope
.
//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;
}
这篇关于使用Windows.Automation,我可以找到由正则表达式的AutomationElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!