wpf中文本框只能输入整数

 private void txtBarCodeNum_KeyUp(object sender, KeyEventArgs e)
{
TxtInt(sender as TextBox);
} private void txtBarCodeNum_TextChanged(object sender, TextChangedEventArgs e)
{
TxtInt(sender as TextBox);
} private void TxtInt(TextBox txt)
{
if (txt==null || string.IsNullOrEmpty(txt.Text))
{
txt.Tag = "";
return;
}
try
{
txt.Text = txt.Text.Trim();
txt.Tag = Convert.ToInt32(txt.Text); ;
}
catch
{
if (txt.Tag==null)
{
txt.Text = "";
}
else
{
txt.Text = txt.Tag.ToString();
}
}
txt.SelectionStart = txt.Text.Length;
}
上一篇:WPF里面制作圆角文本框


下一篇:Silverlight中文本框添加回车事件后,换行无法清除的解决方法