我必须在页面中使用字段,用户名和&密码。当点击输入用户名TextBox我想将焦点移动到PasswordBox时,焦点正确但键盘关闭。如何让键盘保持打开状态?
if (p.OriginalSource is PasswordBox)
{
loginCommand.Execute(null);
}
else if (p.OriginalSource is TextBox) //assuming there is no third box that can handle
{
var element = (p.OriginalSource as TextBox).FindName("passwordbox");
var ss = ((WatermarkPasswordBox)element).Focus();
((WatermarkPasswordBox)element).UpdateLayout();
//((WatermarkPasswordBox)element).Password = "";
}
答案 0 :(得分:0)
为您的用户名文本框创建KeyDown事件,并在事件中编写代码,如此
if (e.Key == System.Windows.Input.Key.Enter)
{
PasswordBox.Focus();
}
这对我有帮助
答案 1 :(得分:0)
对于某种登录屏幕,我处理了用户名字段(TextBox
)的keydown事件,并在enter-keydown事件中将焦点设置为密码字段(PasswordBox
):
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key.Equals(Key.Enter))
{
PasswordBox.Focus();
}
}