I have a simple form, and I would like for the user to move the cursor to the next text box when a user presses on the phoneβs keyboard. Can this be done in Universal Windows Apps? In android, the Next / Done key is displayed on the keyboard to navigate form elements.
You can use FocusManager to programmatically focus.
Use the KeyDown event of a TextBox container, say a StackPanel, to listen for an event on the keyboard. Thus, your code will work as follows
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; } }
For more information about FocusManager, see https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.input.focusmanager.trymovefocus
For more on KeyDown, see https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.keydown
Do you have something like yourTextBoxName.Focus() ..? also use KeyDownEvent for the New Password text box and check the following
yourTextBoxName.Focus()
New Password
if (e.Key == Key.Enter || e.PlatformKeyCode == 0x0A) { confirmPassword.Focus();//change confirmPassword to your controls actual name }