问题
I have a box that I want to take a password of only numbers (like an ATM-card PIN), how is the best way to do that?
Requirements:
- Password (with the hidden numbers)
- Typing digits as the default (only?) keyboard
What I've tried:
I thought that InputScopes would be the way to go, but I can't set the input scope on a password box. I even tried putting the password InputScope on a normal TextBox, but that didn't mask the appearance of the characters in the text box. Suggestions?
回答1:
Short version - you don't out-of-the-box as far as I know.
You're absolutely right that PasswordBox don't support InputScope. I would have thought that it inherited from TextBox or a common ancestor for textual input to get InputScope, but it inherits directly from Control. And since it is a sealed class you cannot inherit it and change it behaviour either. I don't think you can achieve it using ControlTemplate either.
So your best bet will probably be to create your own control mimicking the behaviour of PasswordBox, including the second long delay before the shown character becomes the hidden character.
来源:https://stackoverflow.com/questions/4612757/how-do-i-change-the-on-screen-keyboard-for-a-passwordbox