我需要在 WPF 中明确设置密码框内的光标位置。我在 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();
关于c# - 如何将插入符号位置设置为 WPF 密码框中的特定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/990311/