// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Input { using System.Linq; using Perspex.VisualTree; /// /// TODO: This class is a temporary stop-gap just to add tab handling. Should be replaced /// with something better thought out and testable etc. /// public static class KeyboardNavigation { public static void MoveNext(IInputElement element) { var siblings = element.GetVisualSiblings().OfType() .Where(x => x.Focusable) .SkipWhile(x => x != element) .Skip(1); var next = siblings.FirstOrDefault(); if (next != null) { FocusManager.Instance.Focus(next); } } public static void MovePrevious(IInputElement element) { var siblings = element.GetVisualSiblings().OfType() .Where(x => x.Focusable) .Reverse() .SkipWhile(x => x != element) .Skip(1); var next = siblings.FirstOrDefault(); if (next != null) { FocusManager.Instance.Focus(next); } } } }