WPF의 Password Box에서 Caret 위치를 특정 인덱스로 설정하려면 어떻게해야합니까?
-
13-09-2019 - |
문제
WPF를 명시 적으로 비밀번호 상자 내부에서 cursorposition을 설정해야합니다. PasswordBox에서 SelectionStart 속성을 볼 수 없었습니다.
도움이 있습니까?
해결책
암호 상자에서 선택을 설정하려면 이와 같은 것을 시도 할 수 있습니다.
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