1

如何使用 WPF 将密码框控件与虚拟键盘一起使用?使用文本框控件,只需将插入符号移动到下一个文本位置就相当简单了;密码框不是这样,它不会暴露插入符号的位置。

我应该自己推导出来吗?好像是弱酱。

4

1 回答 1

1

您可以尝试这样的事情来设置 PasswordBox 中的选择:

private void SetSelection(PasswordBox passwordBox, int start, int length) { 
    passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
                         .Invoke(passwordBox, new object[] { start, length }); 
} 

之后,像这样调用它来设置光标位置:

// set the cursor position to 2... or length of the password 
SetSelection( passwordBox1, 2, 0); 

// focus the control to update the selection 
passwordBox1.Focus(); 

上述答案由Andrew Jackson提供,效果很好。

于 2012-03-20T12:56:52.710 回答