c# – 按“Enter”键而不是提交时移动到下一个文本框(Windows Ph
发布时间:2020-12-15 08:14:50 所属栏目:百科 来源:网络整理
导读:我有一个简单的表单,我希望当用户按下手机键盘时,光标将移动到下一个文本框. 这可以在通用 Windows应用程序中完成吗? 在android中,键盘显示Next / Done键以在表单元素中导航. 解决方法 您可以使用FocusManager以编程方式移动焦点. 使用TextBox容器的KeyDown
我有一个简单的表单,我希望当用户按下手机键盘时,光标将移动到下一个文本框.
这可以在通用 Windows应用程序中完成吗? 在android中,键盘显示Next / Done键以在表单元素中导航. 解决方法
您可以使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |