revolutionkpi
revolutionkpi

Reputation: 2682

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?

Upvotes: 1

Views: 394

Answers (1)

Pedro Lamas
Pedro Lamas

Reputation: 7233

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);
}

Upvotes: 1

Related Questions