检查是否选择了AutomationElement。我使用以下代码来获取AutomationElement对象。
System.Windows.Point point = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);
AutomationElement element = AutomationElement.FromPoint(point);
//how to know element is selected or not
答案 0 :(得分:1)
如果您的元素包含在ItemContainer
控件(即ListBox,GridView,ComboBox等)中,那么您可以在元素本身上使用SelectionItem
模式。
SelectionItemPattern selectionItemPattern = element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
bool isSelected = selectionItemPattern.Current.IsSelected;