我试图只TextBox在WPF中创建一个数字,我有这个代码:
void NumericTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValidInput(e.Text);
}
private bool IsValidInput(string p)
{
switch (this.Type)
{
case NumericTextBoxType.Float:
return Regex.Match(p, "^[0-9]*[.][0-9]*$").Success;
case NumericTextBoxType.Integer:
default:
return Regex.Match(p, "^[0-9]*$").Success;
}
}
// And also this!
public enum NumericTextBoxType
{
Integer = 0,
Float = 1
}
Run Code Online (Sandbox Code Playgroud)
当我将类型设置为Integer时,它运行良好,但对于Float,它没有.
我可以使用那么多NumericTextBox控件,但我想知道为什么这个不起作用?