WPF TextBox限制只能输入数字
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
TextBox txt = sender as TextBox;
// 过滤按键
if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9))
{
e.Handled = false;
}
else if (((e.Key >= Key.D0 && e.Key <= Key.D9)))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}