我在WPF上提供了一个文本框
<TextBox TextChanged="txtChange" PreviewTextInput="NumberValidationTextBox" />
对于我所参加的每一项活动:
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex1 = new Regex("[^0-9]+");
e.Handled = regex1.IsMatch(e.Text);
}
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
{
double number = double.Parse(txt.Text.Replace(",", ""));
txt.Text= number.ToString("n0");
txt.Focus();
txt.Select(txt.Text.Length, 0);
}
它的工作正常,我有数字和“,”字符串格式为“000,000,000”
但是在代码中我改变了textbox的选择器,所以这段代码有问题。让我知道我怎么能同时提供