Question

Je dois régler la cursorposition à l'intérieur du PasswordBox explicitlyin WPF. je ne pouvais pas voir la propriété SelectionStart dans PasswordBox.

Toute aide?

Était-ce utile?

La solution

Vous pouvez essayer quelque chose comme ceci pour définir la sélection dans le PasswordBox:

private void SetSelection(PasswordBox passwordBox, int start, int length) {
    passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(passwordBox, new object[] { start, length });
}

Après cela, appeler comme celui-ci pour définir la position du curseur:

// set the cursor position to 2...
SetSelection( passwordBox1, 2, 0);

// focus the control to update the selection
passwordBox1.Focus();

Autres conseils

Non, l'API pour PasswordBox ne pas exposer une façon de le faire.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top