Frage

Ich brauche die Cursor-Position in der PasswordBox explicitlyin WPF zu setzen. Ich konnte nicht die Eigenschaft Selection in PasswordBox sehen.

Jede Hilfe?

War es hilfreich?

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
scroll top