我有一个简单的表单,我希望当用户按下手机键盘时,光标将移动到下一个文本框.这可以在通用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;
}
}
Run Code Online (Sandbox Code Playgroud)
有关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
| 归档时间: |
|
| 查看次数: |
4312 次 |
| 最近记录: |