问题描述
我的文本框中有一个 ExceptionValidationRule
<Window.Resources>
<Style x:Key="textStyleTextBox" TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<TextBox x:Name="myTextBox"
{Binding Path=MyProperty, ValidatesOnExceptions=True}"
Style="{StaticResource ResourceKey=textStyleTextBox}" />
和 MyProperty
p>
and MyProperty
looks like that:
private int myProperty;
public int MyProperty
{
get { return myProperty; }
set
{
if(value > 10)
throw new ArgumentException("LOL that's an error");
myProperty = value;
}
}
在 DEBUG
模式,应用程序崩溃与未处理的异常LOL这是一个错误
(WPF绑定引擎不抓住这个,我认为它应该...)。
In DEBUG
mode, application crashes with unhandled exception "LOL that's an error"
(WPF Binding Engine doesn't catch this and I think it should...).
在 RELEASE
模式中,一切正常。
有人可以告诉我,为什么地狱这个事情呢?我该怎么解决这个问题?
Can someone tell me, why the hell is this happening? And how can I fix this?
推荐答案
解决方案不是很明显,也没有文件证明,但简单。
在调试模式下运行时,Visual Studio中断异常的原因是因为它被配置为这样。
The solution is not so obvious nor well documented, but simple enough.The reason Visual Studio breaks for exceptions when running in debug mode is because it's configured that way.
在调试菜单中,选择例外... 。在此对话框中,您可以控制VS如何处理异常。只需取消选中用户未处理常用语言运行时异常,按确定并再次运行您的项目。
In the Debug menu, select "Exceptions...". In this dialog you control how VS handles exceptions. Simply uncheck "User-unhandled" for "Common Language Runtime Exceptions", press OK and run your project again.
这篇关于ExceptionValidationRule不对异常做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!