ExceptionValidationRule不会对异常做出反应

Dar*_*mak 7 debugging validation wpf exception

我的ExceptionValidationRuleTextBox上有一个:

<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}" />
Run Code Online (Sandbox Code Playgroud)

MyProperty看起来像这样:

private int myProperty;

public int MyProperty
{
    get { return myProperty; }
    set
    {
        if(value > 10)
            throw new ArgumentException("LOL that's an error");
        myProperty = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

DEBUG模式下,应用程序崩溃时出现未处理的异常"LOL that's an error"(WPF绑定引擎没有抓住这个,我认为它应该......).

RELEASE模式中,一切正常.

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

Rey*_*yhn 8

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

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