Example #1
0
        public static bool IsMultiSelectAllowed(this IListBoxUiaMarker uiaListBox)
        {
            var itemToSelect = uiaListBox.AutomationElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

            if (itemToSelect != null)
            {
                var selectItemPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                var selectionPattern  = selectItemPattern.Current.SelectionContainer.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
                return(selectionPattern.Current.CanSelectMultiple);
            }
            return(true);
        }
Example #2
0
        public static string[] GetSelectedItems(this IListBoxUiaMarker uiaListBox)
        {
            var list         = new List <string>();
            var itemToSelect = uiaListBox.AutomationElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

            if (itemToSelect != null)
            {
                var selectItemPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                var selectionPattern  = selectItemPattern.Current.SelectionContainer.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
                list.AddRange(selectionPattern.Current.GetSelection().Select(ae => ae.Current.Name));
            }
            return(list.ToArray());
        }
Example #3
0
        public static void UnSelectItem(this IListBoxUiaMarker uiaListBox, string item)
        {
            Condition cond = new PropertyCondition(
                AutomationElement.NameProperty, item, PropertyConditionFlags.IgnoreCase);

            var itemToSelect = uiaListBox.AutomationElement.FindFirst(TreeScope.Children, cond);

            if (itemToSelect != null)
            {
                var selectItemPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);

                selectItemPattern.RemoveFromSelection();
            }
        }
Example #4
0
        public static string[] GetItems(this IListBoxUiaMarker uiaListBox)
        {
            AutomationElementCollection allItems = uiaListBox.AutomationElement.FindAll(TreeScope.Subtree,
                                                                                        new PropertyCondition(
                                                                                            AutomationElement.
                                                                                            ControlTypeProperty,
                                                                                            ControlType.ListItem));
            var list = new List <string>();

            for (int i = 0; i < allItems.Count; i++)
            {
                list.Add(allItems[i].Current.Name);
            }
            return(list.ToArray());
        }
Example #5
0
        public static void SelectItem(this IListBoxUiaMarker uiaListBox, string item, bool bMultiSelect = true)
        {
            Condition cond = new PropertyCondition(
                AutomationElement.NameProperty, item, PropertyConditionFlags.IgnoreCase);

            var itemToSelect = uiaListBox.AutomationElement.FindFirst(TreeScope.Children, cond);

            if (itemToSelect != null)
            {
                var selectItemPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                var selectionPattern  = selectItemPattern.Current.SelectionContainer.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;

                if (bMultiSelect && selectionPattern.Current.CanSelectMultiple)
                {
                    selectItemPattern.AddToSelection();
                }
                else
                {
                    selectItemPattern.Select();
                }
            }
        }