Beispiel #1
0
        public static DependencyObject?GetDirectionOverride(
            DependencyObject element,
            DependencyObject?searchRoot,
            FocusNavigationDirection direction,
            bool ignoreFocusabililty = false)
        {
            DependencyObject?overrideElement = null;

            DependencyProperty?property = GetXYFocusPropertyIndex(element, direction);

            if (property != null)
            {
                overrideElement = element.GetValue(property) as DependencyObject;

                if (overrideElement != null && (!ignoreFocusabililty && !XYFocusFocusability.IsValidCandidate(overrideElement)))
                {
                    return(null);
                }

                // If an override was specified, but it is located outside the searchRoot, don't use it as the candidate.
                if (searchRoot != null &&
                    overrideElement != null &&
                    searchRoot.IsAncestorOf(overrideElement) == false)
                {
                    return(null);
                }
            }

            return(overrideElement);
        }
Beispiel #2
0
        internal static List <XYFocus.XYFocusParameters> FindElements(
            DependencyObject?startRoot,
            DependencyObject?currentElement,
            DependencyObject?activeScroller,
            bool ignoreClipping,
            bool shouldConsiderXYFocusKeyboardNavigation)
        {
            bool isScrolling = (activeScroller != null);
            List <XYFocus.XYFocusParameters> focusList = new List <XYFocus.XYFocusParameters>(InitialCandidateListCapacity);
            var collection = FocusProperties.GetFocusChildren(startRoot);

            if (collection == null)             // || collection.IsLeaving())
            {
                return(focusList);
            }

            var kidCount = collection.Length;

            //Iterate though every node in the tree that is focusable
            for (uint i = 0; i < kidCount; i++)
            {
                DependencyObject child = collection[i];

                if (child == null)
                {
                    continue;
                }

                bool isEngagementEnabledButNotEngaged = FocusProperties.IsFocusEngagementEnabled(child) && !FocusProperties.IsFocusEngaged(child);

                //This is an element that can be focused
                if (child != currentElement && XYFocusFocusability.IsValidCandidate(child))
                {
                    var parameters = new XYFocus.XYFocusParameters();

                    if (isScrolling)
                    {
                        var scrollCandidate = child;
                        var bounds          = GetBoundsForRanking(scrollCandidate, ignoreClipping);

                        //Include all elements participating in scrolling or
                        //elements that are currently not occluded (in view) or
                        //elements that are currently occluded but part of a parent scrolling surface.
                        if (IsCandidateParticipatingInScroll(scrollCandidate, activeScroller) ||
                            !IsOccluded(scrollCandidate, bounds) ||
                            IsCandidateChildOfAncestorScroller(scrollCandidate, activeScroller))
                        {
                            parameters.Element = scrollCandidate;
                            parameters.Bounds  = bounds;

                            focusList.Add(parameters);
                        }
                    }
                    else
                    {
                        var bounds = GetBoundsForRanking(child, ignoreClipping);

                        parameters.Element = child;
                        parameters.Bounds  = bounds;

                        focusList.Add(parameters);
                    }
                }

                if (IsValidFocusSubtree(child, shouldConsiderXYFocusKeyboardNavigation) && !isEngagementEnabledButNotEngaged)
                {
                    var subFocusList = FindElements(child, currentElement, activeScroller, ignoreClipping, shouldConsiderXYFocusKeyboardNavigation);
                    focusList.AddRange(subFocusList);
                }
            }

            return(focusList);
        }