解决方法
您可以使用FocusManager以编程方式移动焦点.
使用TextBox容器的KeyDown事件(比如说StackPanel)来监听键盘事件.所以你的代码会像这样工作
private void stackPanel_KeyDown(object sender,KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Enter) { if (FocusManager.GetFocusedElement() == inputTextBox) // Change the inputTextBox to your TextBox name { FocusManager.TryMoveFocus(FocusNavigationDirection.Next); FocusManager.TryMoveFocus(FocusNavigationDirection.Next); } else { FocusManager.TryMoveFocus(FocusNavigationDirection.Next); } // Make sure to set the Handled to true,otherwise the RoutedEvent might fire twice e.Handled = true; } }
有关FocusManager的更多详细信息,请参阅https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.input.focusmanager.trymovefocus
有关KeyDown的更多详细信息,请参阅https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.keydown