[英]How can i set the caret position to a specific index in passwordbox in WPF
I need to set the cursorposition inside the passwordbox explicitlyin WPF. 我需要在WPF中显式设置密码框内的cursorposition。 i couldn't see the selectionstart property in passwordbox. 我在passwordbox中看不到selectionstart属性。
Any help? 有帮助吗?
You can try something like this to set the selection in the PasswordBox: 你可以尝试这样的东西来设置PasswordBox中的选择:
private void SetSelection(PasswordBox passwordBox, int start, int length) {
passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(passwordBox, new object[] { start, length });
}
After that, call it like this to set the cursor position: 之后,像这样调用它来设置光标位置:
// set the cursor position to 2...
SetSelection( passwordBox1, 2, 0);
// focus the control to update the selection
passwordBox1.Focus();
不,PasswordBox的API没有公开这样做的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.