private static void ValidateTabNavigationOrder(ItemsRepeater repeater) { var expectedSequence = GetRealizedRange(repeater); expectedSequence.Last().Focus(FocusState.Keyboard); Log.Comment("\n\nStart point: " + expectedSequence.Last().Content); Log.Comment("Validating forward tab navigation..."); foreach (var expectedElement in expectedSequence) { var actualElement = (Button)FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next); Log.Comment("Expected: " + expectedElement.Content); Log.Comment("Actual: " + actualElement.Content); Verify.AreEqual(expectedElement, actualElement); expectedElement.Focus(FocusState.Keyboard); } Log.Comment("Validating backward tab navigation..."); foreach (var expectedElement in expectedSequence.Reverse().Skip(1)) { var actualElement = (Button)FocusManager.FindNextFocusableElement(FocusNavigationDirection.Previous); Log.Comment("Expected: " + expectedElement.Content); Log.Comment("Actual: " + actualElement.Content); Verify.AreEqual(expectedElement, actualElement); expectedElement.Focus(FocusState.Keyboard); } }
private void Shell_KeyDown(object sender, KeyRoutedEventArgs e) { FocusNavigationDirection direction = FocusNavigationDirection.None; switch (e.Key) { case Windows.System.VirtualKey.Space: case Windows.System.VirtualKey.Enter: { var control = FocusManager.GetFocusedElement() as Control; var option = control as RadioButton; if (option != null) { var automation = new RadioButtonAutomationPeer(option); automation.Select(); } } return; // Otherwise. find next focusable element in apprpriate direction case Windows.System.VirtualKey.Left: case Windows.System.VirtualKey.GamepadDPadLeft: case Windows.System.VirtualKey.GamepadLeftThumbstickLeft: case Windows.System.VirtualKey.NavigationLeft: direction = FocusNavigationDirection.Left; break; case Windows.System.VirtualKey.Right: case Windows.System.VirtualKey.GamepadDPadRight: case Windows.System.VirtualKey.GamepadLeftThumbstickRight: case Windows.System.VirtualKey.NavigationRight: direction = FocusNavigationDirection.Right; break; case Windows.System.VirtualKey.Up: case Windows.System.VirtualKey.GamepadDPadUp: case Windows.System.VirtualKey.GamepadLeftThumbstickUp: case Windows.System.VirtualKey.NavigationUp: direction = FocusNavigationDirection.Up; break; case Windows.System.VirtualKey.Down: case Windows.System.VirtualKey.GamepadDPadDown: case Windows.System.VirtualKey.GamepadLeftThumbstickDown: case Windows.System.VirtualKey.NavigationDown: direction = FocusNavigationDirection.Down; break; } if (direction != FocusNavigationDirection.None) { var control = FocusManager.FindNextFocusableElement(direction) as Control; if (control != null) { control.Focus(FocusState.Programmatic); e.Handled = true; } } }
private void CommandBar_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Tab) { e.Handled = true; DependencyObject candidate = null; candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); (candidate as Control).Focus(FocusState.Keyboard); } }
private void AlbumWithTracksResponsiveTemplate_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.OriginalKey == Windows.System.VirtualKey.GamepadLeftThumbstickRight) { (FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right) as Control)?.Focus(FocusState.Keyboard); } else if (e.OriginalKey == Windows.System.VirtualKey.GamepadLeftThumbstickDown) { (FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down) as Control)?.Focus(FocusState.Keyboard); } }
/// <summary> /// This method is a work-around until the bug in FocusManager.TryMoveFocus is fixed. /// </summary> /// <param name="direction">The focus navigation direction.</param> private void TryMoveFocus(FocusNavigationDirection direction) { if (direction == FocusNavigationDirection.Next || direction == FocusNavigationDirection.Previous) { FocusManager.TryMoveFocus(direction); } else { var control = FocusManager.FindNextFocusableElement(direction) as Control; control?.Focus(FocusState.Programmatic); } }
private void MoveUp() { if ((FocusManager.FindNextFocusableElement(FocusNavigationDirection.Previous) is Button)) { return; } FocusManager.TryMoveFocus(FocusNavigationDirection.Previous); if (FocusManager.GetFocusedElement() is MenuFlyoutSeparator) { MoveUp(); } }
/// <summary> /// Default keyboard focus movement for any unhandled keyboarding /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AppShell_KeyDown(object sender, KeyRoutedEventArgs e) { var direction = FocusNavigationDirection.None; switch (e.Key) { case VirtualKey.Left: case VirtualKey.GamepadDPadLeft: case VirtualKey.GamepadLeftThumbstickLeft: case VirtualKey.NavigationLeft: direction = FocusNavigationDirection.Left; break; case VirtualKey.Right: case VirtualKey.GamepadDPadRight: case VirtualKey.GamepadLeftThumbstickRight: case VirtualKey.NavigationRight: direction = FocusNavigationDirection.Right; break; case VirtualKey.Up: case VirtualKey.GamepadDPadUp: case VirtualKey.GamepadLeftThumbstickUp: case VirtualKey.NavigationUp: direction = FocusNavigationDirection.Up; break; case VirtualKey.Down: case VirtualKey.GamepadDPadDown: case VirtualKey.GamepadLeftThumbstickDown: case VirtualKey.NavigationDown: direction = FocusNavigationDirection.Down; break; case VirtualKey.Escape: var temp = false; BackRequested(ref temp); break; } if (direction != FocusNavigationDirection.None) { var control = FocusManager.FindNextFocusableElement(direction) as Control; if (control != null) { control.Focus(FocusState.Programmatic); e.Handled = true; } } }
private static void ValidateTabNavigationOrder(ItemsRepeater repeater) { var expectedSequence = GetRealizedRange(repeater); expectedSequence.Last().Focus(FocusState.Keyboard); Log.Comment("\n\nStart point: " + expectedSequence.Last().Content); Log.Comment("Validating forward tab navigation..."); foreach (var expectedElement in expectedSequence) { var actualElement = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next); var actualElementAsbutton = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next) as Button; var actualElementAsToggleButton = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next) as ToggleButton; string content = actualElementAsbutton != null ? (string)actualElementAsbutton.Content : (string)actualElementAsToggleButton.Content; // We need to ignore the toggle theme button, so lets set its tabstop to false and get next element. if (content == "Toggle theme") { actualElementAsbutton.IsTabStop = false; actualElement = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next); } actualElementAsbutton = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next) as Button; actualElementAsToggleButton = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next) as ToggleButton; content = actualElementAsbutton != null ? (string)actualElementAsbutton.Content : (string)actualElementAsToggleButton.Content; // We need to ignore the lab dimensions button, so lets set its tabstop to false and get next element. if (content == "Render innerframe in lab dimensions") { actualElementAsToggleButton.IsTabStop = false; actualElement = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Next); } Log.Comment("Expected: " + expectedElement.Content); Log.Comment("Actual: " + content); Verify.AreEqual(expectedElement, actualElement); expectedElement.Focus(FocusState.Keyboard); } Log.Comment("Validating backward tab navigation..."); foreach (var expectedElement in expectedSequence.Reverse().Skip(1)) { var actualElement = (Button)FocusManager.FindNextFocusableElement(FocusNavigationDirection.Previous); Log.Comment("Expected: " + expectedElement.Content); Log.Comment("Actual: " + actualElement.Content); Verify.AreEqual(expectedElement, actualElement); expectedElement.Focus(FocusState.Keyboard); } }
/// <summary> /// Default keyboard focus movement for any unhandled keyboarding /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AppShell_KeyDown(object sender, KeyRoutedEventArgs e) { FocusNavigationDirection direction = FocusNavigationDirection.None; switch (e.Key) { case Windows.System.VirtualKey.Left: case Windows.System.VirtualKey.GamepadDPadLeft: case Windows.System.VirtualKey.GamepadLeftThumbstickLeft: case Windows.System.VirtualKey.NavigationLeft: direction = FocusNavigationDirection.Left; break; case Windows.System.VirtualKey.Right: case Windows.System.VirtualKey.GamepadDPadRight: case Windows.System.VirtualKey.GamepadLeftThumbstickRight: case Windows.System.VirtualKey.NavigationRight: direction = FocusNavigationDirection.Right; break; case Windows.System.VirtualKey.Up: case Windows.System.VirtualKey.GamepadDPadUp: case Windows.System.VirtualKey.GamepadLeftThumbstickUp: case Windows.System.VirtualKey.NavigationUp: direction = FocusNavigationDirection.Up; break; case Windows.System.VirtualKey.Down: case Windows.System.VirtualKey.GamepadDPadDown: case Windows.System.VirtualKey.GamepadLeftThumbstickDown: case Windows.System.VirtualKey.NavigationDown: direction = FocusNavigationDirection.Down; break; } if (direction == FocusNavigationDirection.None) { return; } var control = FocusManager.FindNextFocusableElement(direction) as Control; if (control == null) { return; } control.Focus(FocusState.Programmatic); e.Handled = true; }
/// <summary> /// This method is a work-around until the bug in FocusManager.TryMoveFocus is fixed. /// </summary> /// <param name="direction"></param> private void TryMoveFocus(FocusNavigationDirection direction) { if (direction == FocusNavigationDirection.Next || direction == FocusNavigationDirection.Previous) { FocusManager.TryMoveFocus(direction); } else { var control = FocusManager.FindNextFocusableElement(direction) as Windows.UI.Xaml.Controls.Control; if (control != null) { control.Focus(FocusState.Programmatic); } } }
/// <summary> /// Default keyboard focus movement for any unhandled keyboarding /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainPage_KeyDown(object sender, KeyRoutedEventArgs e) { FocusNavigationDirection direction = FocusNavigationDirection.None; switch (e.Key) { case Windows.System.VirtualKey.Left: case Windows.System.VirtualKey.GamepadDPadLeft: case Windows.System.VirtualKey.GamepadLeftThumbstickLeft: case Windows.System.VirtualKey.NavigationLeft: direction = FocusNavigationDirection.Left; break; case Windows.System.VirtualKey.Right: case Windows.System.VirtualKey.GamepadDPadRight: case Windows.System.VirtualKey.GamepadLeftThumbstickRight: case Windows.System.VirtualKey.NavigationRight: direction = FocusNavigationDirection.Right; break; case Windows.System.VirtualKey.Up: case Windows.System.VirtualKey.GamepadDPadUp: case Windows.System.VirtualKey.GamepadLeftThumbstickUp: case Windows.System.VirtualKey.NavigationUp: direction = FocusNavigationDirection.Up; break; case Windows.System.VirtualKey.Down: case Windows.System.VirtualKey.GamepadDPadDown: case Windows.System.VirtualKey.GamepadLeftThumbstickDown: case Windows.System.VirtualKey.NavigationDown: direction = FocusNavigationDirection.Down; break; } if (direction != FocusNavigationDirection.None) { if (FocusManager.FindNextFocusableElement(direction) is Control control) { control.Focus(FocusState.Keyboard); e.Handled = true; } } }
/// <summary> /// This method is a work-around until the bug in FocusManager.TryMoveFocus is fixed. /// </summary> /// <param name="direction"></param> private void TryMoveFocus(FocusNavigationDirection direction) { if (direction == FocusNavigationDirection.Next || direction == FocusNavigationDirection.Previous) { FocusManager.TryMoveFocus(direction); } else { var control = FocusManager.FindNextFocusableElement(direction) as Control; if (control != null) { control.Focus(FocusState.Programmatic); } if (control is ListViewItem) { var item = control as ListViewItem; ScrollIntoView(item.Content); } } }
private void inputButton_KeyDown(object sender, KeyRoutedEventArgs e) { DependencyObject candidate; if (e.Key == Windows.System.VirtualKey.Down) { e.Handled = true; candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); if (candidate != null) { (candidate as Control).Focus(FocusState.Keyboard); } else { candidate = FocusManager.FindFirstFocusableElement(candidate); if (candidate != null) { (candidate as Control).Focus(FocusState.Keyboard); } } } else if (e.Key == Windows.System.VirtualKey.Up) { e.Handled = true; candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up); if (candidate != null) { (candidate as Control).Focus(FocusState.Keyboard); } else { candidate = FocusManager.FindLastFocusableElement(candidate); if (candidate != null) { (candidate as Control).Focus(FocusState.Keyboard); } } } }
private void AppBarButton_GotFocus(object sender, RoutedEventArgs e) { // The default gamepad navigation is awkward in this app due to the way the app lays // out its pages. It is common for users to overshoot when navigating with the gamepad. // If users press Down too many times, they end up on the command bar buttons in // the bottom right corner of the page. Pressing Up doesn't return focus anywhere // close to where it came from because pressing Up puts focus on the search box // because that's the next control in the upward direction. // // Ideally, we would revise the page layout so that there is a clear next control // in each direction. Here, we programmatically set the XYFocusUp property // to the control that is closest to the command bar, which is usually the // bottom-most control in the content frame. var transform = bottomCommandBar.TransformToVisual(null); // Calculate the rectangle that describes the top edge of the bottom command bar. var rect = new Rect(0, 0, bottomCommandBar.ActualWidth, 0); rect = transform.TransformBounds(rect); var destinationElement = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up, rect); searchButton.XYFocusUp = destinationElement; }
// handle keyboard navigation (tabs and gamepad) private void HamburgerMenu_KeyDown(object sender, KeyRoutedEventArgs e) { var currentItem = FocusManager.GetFocusedElement() as FrameworkElement; var lastItem = LoadedNavButtons.FirstOrDefault(x => x.HamburgerButtonInfo == (SecondaryButtons.LastOrDefault(a => a != Selected) ?? PrimaryButtons.LastOrDefault(a => a != Selected))); var focus = new Func <FocusNavigationDirection, bool>(d => { if (d == FocusNavigationDirection.Next) { return(FocusManager.TryMoveFocus(d)); } else if (d == FocusNavigationDirection.Previous) { return(FocusManager.TryMoveFocus(d)); } else { var control = FocusManager.FindNextFocusableElement(d) as Control; return(control?.Focus(FocusState.Programmatic) ?? false); } }); var escape = new Func <bool>(() => { if (DisplayMode == SplitViewDisplayMode.CompactOverlay || DisplayMode == SplitViewDisplayMode.Overlay) { IsOpen = false; } if (Equals(ShellSplitView.PanePlacement, SplitViewPanePlacement.Left)) { ShellSplitView.Content.RenderTransform = new TranslateTransform { X = 48 + ShellSplitView.OpenPaneLength }; focus(FocusNavigationDirection.Right); ShellSplitView.Content.RenderTransform = null; } else { ShellSplitView.Content.RenderTransform = new TranslateTransform { X = -48 - ShellSplitView.OpenPaneLength }; focus(FocusNavigationDirection.Left); ShellSplitView.Content.RenderTransform = null; } return(true); }); var previous = new Func <bool>(() => { if (Equals(currentItem, HamburgerButton)) { return(true); } else if (focus(FocusNavigationDirection.Previous) || focus(FocusNavigationDirection.Up)) { return(true); } else { return(escape()); } }); var next = new Func <bool>(() => { if (Equals(currentItem, HamburgerButton)) { return(focus(FocusNavigationDirection.Down)); } else if (focus(FocusNavigationDirection.Next) || focus(FocusNavigationDirection.Down)) { return(true); } else { return(escape()); } }); if (IsFullScreen) { return; } switch (e.Key) { case VirtualKey.Up: case VirtualKey.GamepadDPadUp: if (!(e.Handled = previous())) { Debugger.Break(); } break; case VirtualKey.Down: case VirtualKey.GamepadDPadDown: if (!(e.Handled = next())) { Debugger.Break(); } break; case VirtualKey.Right: case VirtualKey.GamepadDPadRight: if (SecondaryButtonContainer.Items.Contains(currentItem?.DataContext) && SecondaryButtonOrientation == Orientation.Horizontal) { if (Equals(lastItem.FrameworkElement, currentItem)) { if (!(e.Handled = escape())) { Debugger.Break(); } } else { if (!(e.Handled = next())) { Debugger.Break(); } } } else { if (!(e.Handled = escape())) { Debugger.Break(); } } break; case VirtualKey.Left: case VirtualKey.GamepadDPadLeft: if (SecondaryButtonContainer.Items.Contains(currentItem?.DataContext) && SecondaryButtonOrientation == Orientation.Horizontal) { if (Equals(lastItem.FrameworkElement, currentItem)) { if (!(e.Handled = escape())) { Debugger.Break(); } } else { if (!(e.Handled = previous())) { Debugger.Break(); } } } else { if (!(e.Handled = escape())) { Debugger.Break(); } } break; case VirtualKey.Space: case VirtualKey.Enter: case VirtualKey.GamepadA: if (currentItem != null) { var info = new InfoElement(currentItem); var hamburgerButtonInfo = info.HamburgerButtonInfo; if (hamburgerButtonInfo != null) { NavCommand.Execute(hamburgerButtonInfo); } } break; case VirtualKey.Escape: case VirtualKey.GamepadB: if (!(e.Handled = escape())) { Debugger.Break(); } break; } }
private static bool NavigateUsingKeyboard(KeyEventArgs args, Menu menu, Orientation orientation) { object element; if (ControlHelpers.IsXamlRootAvailable && menu.XamlRoot != null) { element = FocusManager.GetFocusedElement(menu.XamlRoot); } else { element = FocusManager.GetFocusedElement(); } if (element is MenuFlyoutPresenter && ((args.VirtualKey == VirtualKey.Down) || (args.VirtualKey == VirtualKey.Up) || (args.VirtualKey == VirtualKey.Left) || (args.VirtualKey == VirtualKey.Right))) { // Hack to delay and let next element get focus FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right); return(true); } if (!menu.IsOpened && element is MenuItem) { menu.UpdateMenuItemsFlyoutPlacement(); if (args.VirtualKey == VirtualKey.Enter || ((args.VirtualKey == VirtualKey.Down) && menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Bottom) || ((args.VirtualKey == VirtualKey.Up) && menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Top) || ((args.VirtualKey == VirtualKey.Left) && menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Left) || ((args.VirtualKey == VirtualKey.Right) && menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Right)) { menu.SelectedMenuItem.ShowMenu(); return(true); } if ((args.VirtualKey == VirtualKey.Left && orientation == Orientation.Horizontal) || (args.VirtualKey == VirtualKey.Up && orientation == Orientation.Vertical)) { GetNextMenuItem(menu, -1); return(true); } if ((args.VirtualKey == VirtualKey.Right && orientation == Orientation.Horizontal) || (args.VirtualKey == VirtualKey.Down && orientation == Orientation.Vertical)) { GetNextMenuItem(menu, +1); return(true); } } if ((menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Left && args.VirtualKey == VirtualKey.Right) || (args.VirtualKey == VirtualKey.Left && menu.CurrentFlyoutPlacement != FlyoutPlacementMode.Left)) { if (element is MenuFlyoutItem) { menu.IsInTransitionState = true; menu.SelectedMenuItem.HideMenu(); GetNextMenuItem(menu, -1).ShowMenu(); return(true); } if (element is MenuFlyoutSubItem menuFlyoutSubItem) { if (menuFlyoutSubItem.Parent is MenuItem && element == menu._lastFocusElement) { menu.IsInTransitionState = true; menu.SelectedMenuItem.HideMenu(); GetNextMenuItem(menu, -1).ShowMenu(); return(true); } } } if ((args.VirtualKey == VirtualKey.Right && menu.CurrentFlyoutPlacement != FlyoutPlacementMode.Left) || (args.VirtualKey == VirtualKey.Left && menu.CurrentFlyoutPlacement == FlyoutPlacementMode.Left)) { if (element is MenuFlyoutItem) { menu.IsInTransitionState = true; menu.SelectedMenuItem.HideMenu(); GetNextMenuItem(menu, +1).ShowMenu(); return(true); } } return(false); }
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e) { DependencyObject candidate = null; switch (e.OriginalKey) { case VirtualKey.Right: case VirtualKey.GamepadDPadRight: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Left); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.Left: case VirtualKey.GamepadDPadLeft: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Left); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.Up: case VirtualKey.GamepadDPadUp: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.GamepadMenu: NavigationInfo a = new NavigationInfo(); a.language = idioma; a.name = name; this.Frame.Navigate(typeof(MenuPrincipal), a); break; case VirtualKey.Down: case VirtualKey.GamepadDPadDown: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up); } //Casteamos el Objeto que guarda el cambio de foco a un control para establecer eso como foco en focusmanager (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; //Si`por ejemplo quiero hacerlo para quedesde jugar vaya a salir igualo la variable Candidate al boton en cuestion } }
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e) { if (cambiarNombre) { char c = (char)e.Key; //CONTROL PARA QUE SOLO VALGAN LETRAS, NUMEROS ETC if (c >= 65 && c <= 90 || c >= 97 && (int)c <= 122 /*|| (int)c >= 48 && (int)c <= 57*/) //65-90 97-122 48-57 { newName = newName + c; NombrePlayer.Text = newName; } } DependencyObject candidate = null; switch (e.Key) { case VirtualKey.Escape: newName = ""; NombrePlayer.Text = ""; GuardarCambios(); break; case VirtualKey.Enter: GuardarCambios(); break; case VirtualKey.Right: case VirtualKey.GamepadDPadRight: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Left); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.Left: case VirtualKey.GamepadDPadLeft: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Left); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.Up: case VirtualKey.GamepadDPadUp: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); } (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; case VirtualKey.GamepadMenu: NavigationInfo a = new NavigationInfo(); a.language = idioma; a.name = lastName; this.Frame.Navigate(typeof(MenuPrincipal), a); break; case VirtualKey.Down: case VirtualKey.GamepadDPadDown: // el candidato es el primer objeto al navegar hacia abajo en la lista candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Down); // movemos el foco al siguiente objeto if (candidate == null) { candidate = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Up); } //Casteamos el Objeto que guarda el cambio de foco a un control para establecer eso como foco en focusmanager (candidate as Control).Focus(FocusState.Keyboard); e.Handled = true; break; //Si`por ejemplo quiero hacerlo para quedesde jugar vaya a salir igualo la variable Candidate al boton en cuestion } }