Reputation: 219
Check if AutomationElement is selected or not. I have used following code to get an AutomationElement object.
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
Upvotes: 0
Views: 1049
Reputation: 759
If your element is contained in an ItemContainer
control (i.e. ListBox, GridView, ComboBox and so forth), then you can use the SelectionItem
pattern on the element itself.
SelectionItemPattern selectionItemPattern = element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
bool isSelected = selectionItemPattern.Current.IsSelected;
Upvotes: 1