private static bool NavigateCommandFocus(CommandBarNavigationDirection barNavigationDirection) { var sortedNavigationList = GetSortedNavigationList(); var index = sortedNavigationList.FindIndex(control => control.IsKeyboardFocusWithin); if (index < 0) { return(false); } var direction = barNavigationDirection == CommandBarNavigationDirection.Next ? 1 : -1; for (var currentIndex = NextIndex(index, direction, sortedNavigationList.Count); currentIndex != index; currentIndex = NextIndex(currentIndex, direction, sortedNavigationList.Count)) { if (sortedNavigationList[currentIndex] is ItemsControl control) { if (TryEnterCommandBar(control)) { return(true); } else if (TryFocusElementOrDescendant(sortedNavigationList[currentIndex])) { return(true); } } } return(false); }
public bool FilterKeyDownMessage(Key realKey, ModifierKeys modifierKeys, bool isRepeat) { var flag1 = false; if (MenuModeHelper.IsInCommandMode) { if (MenuModeHelper.CommandModeKind == CommandBarModeKind.SearchControl) { if (IsAltKey(realKey) && TestModifierKeys(modifierKeys, ModifierKeys.Shift, ModifierKeys.Control | ModifierKeys.Windows)) { Keyboard.Focus(null); flag1 = true; } else if (ShouldHandleSearchControlEscapeKey(realKey)) { Keyboard.Focus(null); flag1 = true; } } var flag2 = false; if (IsTabKey(realKey) && TestModifierKeys(modifierKeys, ModifierKeys.Control, ModifierKeys.Alt | ModifierKeys.Windows)) { flag2 = true; _cycleDirection = TestModifierKeys(modifierKeys, ModifierKeys.Shift) ? CommandBarNavigationDirection.Previous : CommandBarNavigationDirection.Next; } else if (MenuModeHelper.CommandModeKind == CommandBarModeKind.NavigableControl && TestModifierKeys(modifierKeys, ModifierKeys.None, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Windows)) { if (IsTabKey(realKey)) { flag2 = true; _cycleDirection = TestModifierKeys(modifierKeys, ModifierKeys.Shift) ? CommandBarNavigationDirection.Previous : CommandBarNavigationDirection.Next; } else if (realKey == Key.Left) { flag2 = true; _cycleDirection = CommandBarNavigationDirection.Previous; } else if (realKey == Key.Right) { flag2 = true; _cycleDirection = CommandBarNavigationDirection.Next; } else if (realKey == Key.Escape) { Keyboard.Focus(null); flag1 = true; } } if (flag2) { if (_encounteredTabKey == Key.None) { _encounteredTabKey = realKey; _isInTabCycle = true; } if (_isInTabCycle) { flag1 = NavigateCommandFocus(_cycleDirection); } } } else { _isInTabCycle = false; _encounteredTabKey = Key.None; } return(flag1); }