Reputation: 933
In my windows app there is a textfield to input numbers(binary 1 or 0) for users. I'm building this app to convert binary numbers into decimal. Now What I want is , when user enter a binary number in textfield, other numbers should disable, or should give an error message. help me with this. thanx.!!!!
Upvotes: 0
Views: 116
Reputation: 2774
For Windows Phone 8 - Silverlight Application.
Hook to your Textbox's KeyDown Event;
private void yourTextbox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
// Check for 1 & 0
if ((e.PlatformKeyCode != 48) || (e.PlatformKeyCode != 49) || (e.PlatformKeyCode != 8))
{ e.Handled = true; }
}
Don't forget to set you Textbox's InputScope="Number"
in XAML.
Upvotes: 1
Reputation: 16361
Hook into the KeyUp
event of the TextBox
and check if the key is 0 or 1. If not, simply delete it.
Upvotes: 1