ExceptionValidationRule不会对异常做出反应

时间:2010-04-30 21:54:43

标签: wpf debugging validation exception

我的TextBox上有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看起来像这样:

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 that's an error"(WPF绑定引擎无法捕获此内容,我认为它应该......)。

RELEASE模式下,一切正常。

有人可以告诉我,为什么地狱会发生这种情况?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:8)

解决方案不是那么明显,也没有很好的文档记录,但足够简单。 在调试模式下运行时Visual Studio因异常而中断的原因是因为它以这种方式配置。

在“调试”菜单中,选择“例外...”。在此对话框中,您可以控制VS如何处理异常。只需取消选中“公共语言运行时异常”的“用户未处理”,按“确定”再次运行项目。

相关问题