[英]How can i set the caret position to a specific index in passwordbox in WPF
我需要在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沒有公開這樣做的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.