/// <summary>
        /// Returns true if in <paramref name="elementPeer"/> parents chain there is an UIElement with
        /// ImportantForAccessibility value of Yes or NoHideDescendants or (Auto and AccessibilityLabelAttached attached property is set).
        /// 'Yes' or (Auto and AccessibilityLabelAttached attached property is set) denotes that the element is visible
        /// to the narrator as a container i.e. its children are 'hidden'. 'NoHideDescendants' denotes that both
        /// the element and its children are 'hidden'. 'Hidden' children have AccessibilityView set to 'Raw'.
        /// </summary>
        /// <param name="elementPeer"></param>
        /// <returns></returns>
        private static bool IsHiddenByAncestor(AutomationPeer elementPeer)
        {
            if (elementPeer == null)
            {
                return(false);
            }

            bool result;

            switch (elementPeer.Navigate(AutomationNavigationDirection.Parent))
            {
            case FrameworkElementAutomationPeer parentFEAutomationPeer:
                if (parentFEAutomationPeer.Owner != null)
                {
                    if (DoesHideDescendants(parentFEAutomationPeer.Owner))
                    {
                        return(true);
                    }
                }
                result = IsHiddenByAncestor(parentFEAutomationPeer);
                break;

            case ItemAutomationPeer parentIAutomationPeer:
                if (parentIAutomationPeer.Item is UIElement parentUIElement)
                {
                    if (DoesHideDescendants(parentUIElement))
                    {
                        return(true);
                    }
                }
                result = IsHiddenByAncestor(parentIAutomationPeer);
                break;

            case AutomationPeer parentAutomationPeer:
                result = IsHiddenByAncestor(parentAutomationPeer);
                break;

            case null:
                result = false;
                break;

            default:
                result = false;
                break;
            }

            return(result);
        }
        internal override void Invoke()
        {
            var peer = FrameworkElementAutomationPeer.FromElement(TargetElement);
            var comboBoxItemAutomationPeer = peer as ComboBoxItemAutomationPeer;
            var comboBoxItem = (ComboBoxItem)comboBoxItemAutomationPeer.Owner;

            AutomationPeer ancestor = comboBoxItemAutomationPeer;
            var            comboBoxAutomationPeer = ancestor as ComboBoxAutomationPeer;

            while (comboBoxAutomationPeer == null)
            {
                ancestor = ancestor.Navigate(AutomationNavigationDirection.Parent) as AutomationPeer;
                comboBoxAutomationPeer = ancestor as ComboBoxAutomationPeer;
            }

            comboBoxItem.IsSelected = true;
            comboBoxAutomationPeer.Collapse();
        }
예제 #3
0
        private static void ComboBoxItemAction(UIElement element)
        {
            var peer = FrameworkElementAutomationPeer.FromElement(element);
            var comboBoxItemAutomationPeer = peer as ComboBoxItemAutomationPeer;
            var comboBoxItem = (ComboBoxItem)comboBoxItemAutomationPeer.Owner;

            AutomationPeer ancestor = comboBoxItemAutomationPeer;
            var            comboBoxAutomationPeer = ancestor as ComboBoxAutomationPeer;

            while (comboBoxAutomationPeer == null)
            {
                ancestor = ancestor.Navigate(AutomationNavigationDirection.Parent) as AutomationPeer;
                comboBoxAutomationPeer = ancestor as ComboBoxAutomationPeer;
            }

            comboBoxItem.IsSelected = true;
            comboBoxAutomationPeer.Collapse();
        }