【发布时间】:2011-05-27 14:01:10
【问题描述】:
如果我有以下文本框:
<TextBox Height="30" Width="300" Margin="10" Text="{Binding IntProperty,
NotifyOnValidationError=True}" Validation.Error="ContentPresenter_Error">
</TextBox>
这在代码隐藏中:
private void ContentPresenter_Error(object sender, ValidationErrorEventArgs e) {
MessageBox.Show(e.Error.ErrorContent.ToString());
}
如果我在文本框中输入字母“x”,弹出的信息是
值“x”无法转换
有没有办法自定义这条消息?
【问题讨论】:
-
为什么不把你自己的字符串放在 MessageBox.Show(); 中?
-
因为我可能有很多其他的文本框,如果有一个验证错误处理程序只接受最新验证错误的错误内容,那就太好了。