Example #1
0
            public int Compare(Stop x, Stop y)
            {
                Point relativePosition1 = KeyboardNavigationTarget.GetLeftBoundPosition(KeyboardNavigationTarget.GetAbsoluteBounds(x.Element)) - currentPosition;
                Point relativePosition2 = KeyboardNavigationTarget.GetLeftBoundPosition(KeyboardNavigationTarget.GetAbsoluteBounds(y.Element)) - currentPosition;

                double distance1 = relativePosition1.X < 0 ? -relativePosition1.GetLengthSqr() : relativePosition1.GetLengthSqr();
                double distance2 = relativePosition2.X < 0 ? -relativePosition2.GetLengthSqr() : relativePosition2.GetLengthSqr();

                return(distance1.CompareTo(distance2));
            }
Example #2
0
            public override IEnumerable <Stop> GetGlobalStops(Visual scope, Visual currentElement, DependencyProperty navigationModeProperty)
            {
                int scopeTabIndex = KeyboardNavigation.GetTabIndex(scope);

                if (IsStop((UIElement)scope) || scope == currentElement)
                {
                    yield return(new Stop(scope, scopeTabIndex));
                }

                // translate stops to have scope tab index instead of local tab index, local order is kept
                foreach (Stop stop in scope.VisualChildren.SelectMany(child => KeyboardNavigationTarget.GetGlobalStops(child, currentElement, navigationModeProperty)).OrderBy(childStop => childStop.TabIndex))
                {
                    yield return(new Stop(stop.Element, scopeTabIndex));
                }
            }
Example #3
0
            public override IEnumerable <Stop> GetGlobalStops(Visual scope, Visual currentElement, DependencyProperty navigationModeProperty)
            {
                if (IsStop((UIElement)scope) || scope == currentElement)
                {
                    yield return(new Stop(scope));
                }

                VisualWeakReference navigationFocusElementReference = KeyboardNavigation.GetNavigationFocusElement(scope);
                Visual navigationFocusElement = navigationFocusElementReference != null ? navigationFocusElementReference.Visual : null;

                Stop[] stops = scope.VisualChildren.SelectMany(child => KeyboardNavigationTarget.GetGlobalStops(child, currentElement, navigationModeProperty)).ToArray();

                if (stops.Any())
                {
                    stops = stops.Where(stop => stop.Element == currentElement || stop.Element == navigationFocusElement).DefaultIfEmpty(stops.First()).ToArray();

                    foreach (Stop stop in stops)
                    {
                        yield return(stop);
                    }
                }
            }
Example #4
0
        private void OnPostProcessKey(object sender, KeyEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            FocusNavigationDirection navigationDirection;
            DependencyProperty       navigationModeProperty;

            if (TryGetNavigationMode(e, out navigationModeProperty, out navigationDirection))
            {
                UIElement currentTarget = (UIElement)presentationSource.KeyboardDevice.Target ?? presentationSource.RootElement;

                UIElement newTarget = (UIElement)KeyboardNavigationTarget.FindTarget(currentTarget, navigationDirection, navigationModeProperty);

                if (currentTarget != newTarget && newTarget != null)
                {
                    newTarget.Focus();
                }

                e.Handled = true;
            }
        }
Example #5
0
 public RightBoundStopComparer(Stop currentStop)
 {
     currentPosition = KeyboardNavigationTarget.GetRightBoundPosition(KeyboardNavigationTarget.GetAbsoluteBounds(currentStop.Element));
 }
Example #6
0
 public override Visual FindPreviousTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider)
 {
     return(KeyboardNavigationTarget.FindPreviousContainedTarget(scope, currentStop, navigationModeProperty, stopComparerProvider) ??
            (scope.VisualParent != null ? KeyboardNavigationTarget.FindPreviousTarget(scope.VisualParent, new Stop(currentStop.Element, KeyboardNavigation.GetTabIndex(scope)), navigationModeProperty, stopComparerProvider) : null)); // translate currentStop and forward request to parent
 }
Example #7
0
 public override Visual FindLastTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider)
 {
     return(KeyboardNavigationTarget.FindLastContainedTarget(scope, currentStop, navigationModeProperty, stopComparerProvider));
 }
Example #8
0
 public override Visual FindPreviousTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider)
 {
     return(KeyboardNavigationTarget.FindPreviousContainedTarget(scope, currentStop, navigationModeProperty, stopComparerProvider) ?? currentStop.Element); // stay at the edge
 }
Example #9
0
            public override IEnumerable <Stop> GetGlobalStops(Visual scope, Visual currentElement, DependencyProperty navigationModeProperty)
            {
                if (IsStop((UIElement)scope) || scope == currentElement)
                {
                    yield return(new Stop(scope));
                }

                // add currentElement stop if it's a descendant of scope
                if (scope.IsAncestorOf(currentElement))
                {
                    IEnumerable <Stop> childrenStop = scope.VisualChildren.SelectMany(child => KeyboardNavigationTarget.GetGlobalStops(child, currentElement, navigationModeProperty));
                    yield return(childrenStop.First(childStop => childStop.Element == currentElement));
                }
            }
Example #10
0
 public override Visual FindPreviousTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider)
 {
     // forward the request to the parent
     return(scope.VisualParent != null?KeyboardNavigationTarget.FindPreviousTarget(scope.VisualParent, currentStop, navigationModeProperty, stopComparerProvider) : null);
 }
Example #11
0
 public virtual IEnumerable <Stop> GetGlobalStops(Visual scope, Visual currentElement, DependencyProperty navigationModeProperty)
 {
     return(KeyboardNavigationTarget.GetContainedStops(scope, currentElement, navigationModeProperty));
 }
Example #12
0
 public virtual Visual FindLastTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider)
 {
     return(scope.VisualParent != null?
            KeyboardNavigationTarget.FindLastTarget(scope.VisualParent, currentStop, navigationModeProperty, stopComparerProvider) :
                KeyboardNavigationTarget.FindLastContainedTarget(scope, currentStop, navigationModeProperty, stopComparerProvider));
 }