![]() PinCode = GetNewPasscode(ref pinCode, e) įield.Text = Regex.Replace(pinCode, _passwordChar) įield.SelectionStart = modify new passcode according to entered key Private void PasswordTextBox_KeyUp(object sender, KeyRoutedEventArgs e, TextBox field, ref string pinCode) Also, notice that I am wiring the KeyUp event. Here is the code snippet: Īs you can see above, I am using a TextBox in the XAML for the PIN number and using normal TextAlignment to center the text and InputScope for binding the Number Key pad instead of the default alpha keyboard. In my scenario, I needed the textbox to act like a PIN number (Password) field, so I only accepted numbers as you can see in the code below. You need to be careful though when handling these events, because you could end up making your text fields unusable. ![]() I had this exact requirement 2 weeks ago and I had to solve it, so this blog talks about the approach I took to make this happen.īasically all I needed to do was to switch from using password boxes to a normal textbox and then wire the key up event in the background to hide the entered password. As a consequence, you cannot do many of the things that you normally do with a textbox like customizing the appearance of the password textbox (say you want to make the text center-aligned, or you want to bind the number key pad instead of the alpha keyboard). In the Windows XAML world, a bad design decision was made to have the passwordBox and the TextBox different, meaning that the PasswordBox does not inherit common properties from the TextBox. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |