Reputation: 10971
I have a windows phone page with the following UI markup:
<StackPanel Orientation="Vertical">
<TextBox Name="txtName"/>
<PasswordBox Name="txtPassword"/>
<Button Name="btnLogin" Content="Login"/>
<StackPanel>
What I want to do: After the user types the user name and clicks the "Enter" key on the keyboard, I want the focus to move to the next "txtPassword" TextBox
, then when presses "Enter" the focus moves to the button and so on...
How can I achieve this ?
Upvotes: 1
Views: 2459
Reputation: 1576
Xaml:
<StackPanel Orientation="Vertical">
<TextBox x:Name="txtName" KeyDown="TxtName_KeyDown" />
<PasswordBox x:Name="txtPassword" KeyDown="TxtPassword_KeyDown"/>
<Button x:Name="btnLogin" Content="Login" />
</StackPanel>
Cs:
private void TxtName_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
txtPassword.Focus();
}
private void TxtPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
btnLogin.Focus();
}
Useful info: Determining the Enter key is pressed in a TextBox
Upvotes: 3