Most desktop applications use the Tab key to jump focus from one control to the next one, and this is expected behavior and common knowledge to most users.
On Android, the on-screen keyboard normally shows a “Next” key to - yes, you’ve guessed it! - go to the next field, and that is something really useful when filling long forms!
In truth, some native Windows Phone apps actually do this on some fields, where tapping the Enter key will have the same result, but unfortunately this is not the default behavior.
You could simulate this behavior using the TextBox.KeyUp or TextBox.KeyDown events, and then calling Control.Focus() on the next control you want to get focus, but I guess we can all agree that this is quite some work and if you change the fields order, you’d have to change the code accordingly.
The Cimbalino Windows Phone Toolkit way
Yes, that’s really all it takes, as the behavior contains the everything needed to manage TextBox/PasswordBox control focus changes on Enter key, with some added bonus:
TabIndexproperty value from controls will be taken into account and the order will be respected
- Any control with
IsEnabled = false,
Visibility = Collapsed, or
TabStop = falsewill be skipped
AcceptsEnter = truewill just use the default expected behavior (tapping Enter will just add a new line)
AutoFocusBehavior.CycleNavigationproperty controls whether focus will jump from last control to first one or just focus the full page
AutoFocusBehavior.SelectAllOnFocusproperty controls whether the entire contents of a control will be selected on focus
There is also an
AfterAutoFocus event and
AfterAutoFocusCommand so you can easily add some extra behavior of yours to the current one! :)