答案 0 :(得分:7)
您可以使用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
答案 1 :(得分:0)
yourTextBoxName.Focus()
的东西吗?还可以使用KeyDownEvent来New Password
文本框并检查以下内容
if (e.Key == Key.Enter || e.PlatformKeyCode == 0x0A)
{
confirmPassword.Focus();//change confirmPassword to your controls actual name
}