/// <summary> /// Gets the focusable descendants of the specified element. /// </summary> /// <param name="element">The element.</param> /// <param name="direction">The tab direction. Must be Next or Previous.</param> /// <returns>The element's focusable descendants.</returns> private static IEnumerable <IInputElement> GetFocusableDescendants(IInputElement element, NavigationDirection direction) { var mode = KeyboardNavigation.GetTabNavigation((InputElement)element); if (mode == KeyboardNavigationMode.None) { yield break; } var children = element.GetVisualChildren().OfType <IInputElement>(); if (mode == KeyboardNavigationMode.Once) { var active = KeyboardNavigation.GetTabOnceActiveElement((InputElement)element); if (active != null) { yield return(active); yield break; } else { children = children.Take(1); } } foreach (var child in children) { var customNext = GetCustomNext(child, direction); if (customNext.handled) { yield return(customNext.next); } else { if (child.CanFocus() && KeyboardNavigation.GetIsTabStop((InputElement)child)) { yield return(child); } if (child.CanFocusDescendants()) { foreach (var descendant in GetFocusableDescendants(child, direction)) { if (KeyboardNavigation.GetIsTabStop((InputElement)descendant)) { yield return(descendant); } } } } } }
/// <summary> /// Gets the focusable descendents of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendents.</returns> private static IEnumerable <IInputElement> GetFocusableDescendents(IInputElement element) { var mode = KeyboardNavigation.GetTabNavigation((InputElement)element); if (mode == KeyboardNavigationMode.None) { yield break; } var children = element.GetVisualChildren().OfType <IInputElement>(); if (mode == KeyboardNavigationMode.Once) { var active = KeyboardNavigation.GetTabOnceActiveElement((InputElement)element); if (active != null) { yield return(active); yield break; } else { children = children.Take(1); } } foreach (var child in children) { if (child.CanFocus()) { yield return(child); } if (child.CanFocusDescendents()) { foreach (var descendent in GetFocusableDescendents(child)) { yield return(descendent); } } } }
/// <summary> /// Gets the focusable descendants of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendants.</returns> private static IEnumerable <IInputElement> GetFocusableDescendants(IInputElement element) { var children = element.GetVisualChildren().OfType <IInputElement>(); foreach (var child in children) { if (child.CanFocus()) { yield return(child); } if (child.CanFocusDescendants()) { foreach (var descendant in GetFocusableDescendants(child)) { yield return(descendant); } } } }
/// <summary> /// Gets the focusable descendents of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendents.</returns> private static IEnumerable <IInputElement> GetFocusableDescendents(IInputElement element) { var mode = KeyboardNavigation.GetDirectionalNavigation((InputElement)element); var children = element.GetVisualChildren().OfType <IInputElement>(); foreach (var child in children) { if (child.CanFocus()) { yield return(child); } if (child.CanFocusDescendents()) { foreach (var descendent in GetFocusableDescendents(child)) { yield return(descendent); } } } }
/// <summary> /// Gets the focusable descendents of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendents.</returns> private static IEnumerable<IInputElement> GetFocusableDescendents(IInputElement element) { var mode = KeyboardNavigation.GetDirectionalNavigation((InputElement)element); var children = element.GetVisualChildren().OfType<IInputElement>(); foreach (var child in children) { if (child.CanFocus()) { yield return child; } if (child.CanFocusDescendents()) { foreach (var descendent in GetFocusableDescendents(child)) { yield return descendent; } } } }
/// <summary> /// Gets the focusable descendents of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendents.</returns> private static IEnumerable<IInputElement> GetFocusableDescendents(IInputElement element) { var mode = KeyboardNavigation.GetTabNavigation((InputElement)element); if (mode == KeyboardNavigationMode.None) { yield break; } var children = element.GetVisualChildren().OfType<IInputElement>(); if (mode == KeyboardNavigationMode.Once) { var active = KeyboardNavigation.GetTabOnceActiveElement((InputElement)element); if (active != null) { yield return active; yield break; } else { children = children.Take(1); } } foreach (var child in children) { if (child.CanFocus()) { yield return child; } if (child.CanFocusDescendents()) { foreach (var descendent in GetFocusableDescendents(child)) { yield return descendent; } } } }
/// <summary> /// Gets the previous item that should be focused in the specified container. /// </summary> /// <param name="element">The starting element/</param> /// <param name="container">The container.</param> /// <returns>The previous element, or null if the element is the first.</returns> private static IInputElement GetPreviousInContainer(IInputElement element, IInputElement container) { return container.GetVisualChildren() .OfType<IInputElement>() .Where(CanFocus) .TakeWhile(x => x != element) .LastOrDefault(); }
/// <summary> /// Gets the next item that should be focused in the specified container. /// </summary> /// <param name="element">The starting element/</param> /// <param name="container">The container.</param> /// <returns>The next element, or null if the element is the last.</returns> private static IInputElement GetNextInContainer(IInputElement element, IInputElement container) { var descendent = GetDescendents(element).FirstOrDefault(); if (descendent != null) { return descendent; } else if (container != null) { var sibling = container.GetVisualChildren() .OfType<IInputElement>() .Where(CanFocus) .SkipWhile(x => x != element) .Skip(1) .FirstOrDefault(); if (sibling != null) { return sibling; } } return null; }
/// <summary> /// Gets the focusable descendents of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The element's focusable descendents.</returns> private static IEnumerable<IInputElement> GetFocusableDescendents(IInputElement element) { var children = element.GetVisualChildren().OfType<IInputElement>(); foreach (var child in children) { if (child.CanFocus()) { yield return child; } if (child.CanFocusDescendents()) { foreach (var descendent in GetFocusableDescendents(child)) { yield return descendent; } } } }