解决方法
您可以使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。