简体   繁体   中英

Custom Control in Windows Phone: Creating Numeric PasswordBox

I have a custom TextBlock with my custom validation, but I also need to use a Password Box functionality to. How can I make a custom Numeric PasswordBox?

Just add a PasswordBox to your XAML like so:

<PasswordBox x:Name="MyPasswordBox" KeyDown="MyPasswordBox_KeyDown" />

And then use the KeyDown event to remove all key presses that are not from 0 to 9, like so:

private void MyPasswordBox_KeyDown(object sender, KeyEventArgs e)
{
    e.Handled = (e.Key < Key.D0 || e.Key > Key.D9);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM