// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. namespace Avalonia.Input { /// /// Describes how focus should be moved by directional or tab keys. /// public enum NavigationDirection { /// /// Move the focus to the next control in the tab order. /// Next, /// /// Move the focus to the previous control in the tab order. /// Previous, /// /// Move the focus to the first control in the tab order. /// First, /// /// Move the focus to the last control in the tab order. /// Last, /// /// Move the focus to the left. /// Left, /// /// Move the focus to the right. /// Right, /// /// Move the focus up. /// Up, /// /// Move the focus down. /// Down, /// /// Move the focus up a page. /// PageUp, /// /// Move the focus down a page. /// PageDown, } public static class NavigationDirectionExtensions { /// /// Checks whether a represents a tab movement. /// /// The direction. /// /// True if the direction represents a tab movement ( /// or ); otherwise false. /// public static bool IsTab(this NavigationDirection direction) { return direction == NavigationDirection.Next || direction == NavigationDirection.Previous; } /// /// Checks whether a represents a directional movement. /// /// The direction. /// /// True if the direction represents a directional movement (any value except /// and ); /// otherwise false. /// public static bool IsDirectional(this NavigationDirection direction) { return direction > NavigationDirection.Previous || direction <= NavigationDirection.PageDown; } /// /// Converts a keypress into a . /// /// The key. /// The keyboard modifiers. /// /// A if the keypress represents a navigation keypress. /// public static NavigationDirection? ToNavigationDirection( this Key key, KeyModifiers modifiers = KeyModifiers.None) { switch (key) { case Key.Tab: return (modifiers & KeyModifiers.Shift) != 0 ? NavigationDirection.Next : NavigationDirection.Previous; case Key.Up: return NavigationDirection.Up; case Key.Down: return NavigationDirection.Down; case Key.Left: return NavigationDirection.Left; case Key.Right: return NavigationDirection.Right; case Key.Home: return NavigationDirection.First; case Key.End: return NavigationDirection.Last; case Key.PageUp: return NavigationDirection.PageUp; case Key.PageDown: return NavigationDirection.PageDown; default: return null; } } } }