如何使用WPF将密码箱控件与虚拟键盘一起使用?使用文本框控件,将插入符号移动到下一个文本位置非常简单;密码盒不是这样,它不会暴露插入位置。
我应该自己推导出来吗?看起来像弱酱。
答案 0 :(得分: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提供,效果很好。