我有一个从该方法中AutomationPattern
检索到的对象列表。AutomationElement.GetSupportedPatterns()
现在我需要知道那里有什么样的模式,我的意思是单项InvokePattern
或ExpandCollapsePattern
. 更具体地说,假设我们有一个AutomationPattern
对象,并且我们知道ProgrammaticName
该对象的属性是“InvokePatternIdentifiers.Pattern”字符串,我能以某种方式获得类型的对象InvokePattern
吗?
我已经使用属性和一个大的 switch 语句实现了我自己解决这个问题的方法AutomationPattern.ProgrammaticName
,还有其他方法可以做到这一点吗?
这是我的实现:
public object GetActualAutomationPattern(AutomationElement element, AutomationPattern pattern)
{
switch (pattern.ProgrammaticName)
{
case "DockPatternIdentifiers.Pattern":
return element.GetCurrentPattern(DockPattern.Pattern) as DockPattern;
case "ExpandCollapsePatternIdentifiers.Pattern":
return element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
case "GridPatternIdentifiers.Pattern":
return element.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
case "GridItemPatternIdentifiers.Pattern":
return element.GetCurrentPattern(GridItemPattern.Pattern) as GridItemPattern;
case "InvokePatternIdentifiers.Pattern":
return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
case "MultipleViewPatternIdentifiers.Pattern":
return element.GetCurrentPattern(MultipleViewPattern.Pattern) as MultipleViewPattern;
case "RangeValuePatternIdentifiers.Pattern":
return element.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
case "ScrollPatternIdentifiers.Pattern":
return element.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;
case "ScrollItemPatternIdentifiers.Pattern":
return element.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
case "SelectionPatternIdentifiers.Pattern":
return element.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
case "SelectionItemPatternIdentifiers.Pattern":
return element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
case "TablePatternIdentifiers.Pattern":
return element.GetCurrentPattern(TablePattern.Pattern) as TablePattern;
case "TableItemPatternIdentifiers.Pattern":
return element.GetCurrentPattern(TableItemPattern.Pattern) as TableItemPattern;
case "TogglePatternIdentifiers.Pattern":
return element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
case "TransformPatternIdentifiers.Pattern":
return element.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;
case "ValuePatternIdentifiers.Pattern":
return element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
case "WindowPatternIdentifiers.Pattern":
return element.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
default:
return pattern;
}
}