我如何可以设置在WPF passwordbox尖号位置设置特定索引
-
13-09-2019 - |
题
我需要设置passwordbox explicitlyin WPF内的cursorposition。我不能看到在passwordbox的selectionstart属性。
任何帮助?
解决方案
您可以尝试这样的事情来设置在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...
SetSelection( passwordBox1, 2, 0);
// focus the control to update the selection
passwordBox1.Focus();
其他提示
没有,对于PasswordBox API不露出的方式来做到这一点。
不隶属于 StackOverflow