I want to design a numeric textbox in silverlight.
I have added keydown event of TextBox to handle the keypress.
Inside event I validate the key entered in the textbox.
event as follows
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (!this.Validate(sender,e))
e.Handled = true;
}
function Validate as follows
private bool Validate(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) //accept enter and tab
{
return true;
}
if (e.Key == Key.Tab)
{
return true;
}
if (e.Key < Key.D0 || e.Key > Key.D9) //accept number on alphnumeric key
if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9) //accept number fomr NumPad
if (e.Key != Key.Back) //accept backspace
return false;
return true;
}
I am not able to detect shift and Key.D0 to Key.D1 i.e.
SHIFT + 1 which returns "!"
SHIFT + 3 returns "#" like wise any other special keys.
I dont want user to enter special character in to textbox.
How do i handle this keys event??