views:

87

answers:

0

Hi, I have an ExceptionValidationRule on my TextBox:

<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}" />

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;
    }
}

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...).

In RELEASE mode, everything works fine.

Can someone tell me, why the hell is this happening? And how can I fix this?