Navigating Between Input Controls with the Keyboard
Problem
There is no easy way to denote the next control to receive focus when the Enter key is pressed while entering input in a control such as a TextBox
or PasswordBox
.
Solution
The InputExtensions
class provides a set of attached properties that can be used to manage focus between input controls using the Enter key.
<TextBox PlaceholderText="Username"
utu:InputExtensions.AutoFocusNextElement="{Binding ElementName=RegistrationEmail}" />
<TextBox x:Name="RegistrationEmail"
PlaceholderText="Email"
utu:InputExtensions.AutoFocusNextElement="{Binding ElementName=RegistrationPassword}" />
<PasswordBox x:Name="RegistrationPassword"
PlaceholderText="Password" />
The above code has the following effect:
