Wie kann ich die Position der Einfügemarke auf einen bestimmten Index in PasswordBox in WPF
-
13-09-2019 - |
Frage
Ich brauche die Cursor-Position in der PasswordBox explicitlyin WPF zu setzen. Ich konnte nicht die Eigenschaft Selection in PasswordBox sehen.
Jede Hilfe?
Lösung
Sie können so etwas wie diese versuchen, die Auswahl der PasswordBox zu setzen:
private void SetSelection(PasswordBox passwordBox, int start, int length) {
passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(passwordBox, new object[] { start, length });
}
Danach rufen Sie es wie folgt die Cursor-Position zu setzen:
// set the cursor position to 2...
SetSelection( passwordBox1, 2, 0);
// focus the control to update the selection
passwordBox1.Focus();
Andere Tipps
Nein, die API für PasswordBox aussetzt keinen Weg, dies zu tun.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow