【发布时间】:2013-05-29 15:24:05
【问题描述】:
为了在事件 args 中获得 TextBox 的 Text,我应该订阅什么事件?
我试过PreviewTextInput,但如果输入字符串是,例如,“122”。框的(见代码)文本没有点,但 eventArgs.Text 是“。”输入字符串验证成功,TextBox.Text 为“122..”。我想要做的是通过调用decimal.TryParse 来验证输入字符串是否为十进制。
private void OnPreviewTextInput(object sender, TextCompositionEventArgs eventArgs)
{
var box = sender as TextBox;
if (box == null) return;
eventArgs.Handled = !ValidationUtils.IsValid(box.Text + eventArgs.Text);
}
【问题讨论】:
标签: c# wpf validation textbox decimal