我有一个带有以下UI标记的Windows手机页面:
<StackPanel Orientation="Vertical">
<TextBox Name="txtName"/>
<PasswordBox Name="txtPassword"/>
<Button Name="btnLogin" Content="Login"/>
<StackPanel>
我想做的事情:在用户输入用户名并单击键盘上的“Enter”键后,我希望焦点移动到下一个“txtPassword”TextBox
,然后按“Enter” “焦点移动到按钮等等......
我怎样才能做到这一点?
答案 0 :(得分:3)
<强>的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();
}