kapill
kapill

Reputation: 219

Is there any way to get if an AutomationElement is selected or not

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

Answers (1)

Tal Bronfer
Tal Bronfer

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

Related Questions