//前台UI设置
<TextBox Width="100" Height="30" PreviewTextInput="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" InputMethod.IsInputMethodEnabled="False"/>
InputMethod.IsInputMethodEnabled="False"禁用输入法 后台代码限定只能输入数字
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
short val;
if (!Int16.TryParse(e.Text, out val))
e.Handled = true;
}
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
e.Handled = true;
}