I am working on a textbox using WPF where I want to press only A,B,C,D,E,F and 0-9 that means hexadecimal number. But in my keydown event I can't disable lower char a,b,c,d,e,f. My code is belown:
private void txtHex_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key >= Key.A && e.Key <= Key.F)
{
e.Handled = false;
}
else if (e.Key < Key.D0 || e.Key > Key.D9)
{
if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
{
e.Handled = true;
}
}
}
How can I solve this?
Thanks in advance.