2010-04-30 71 views
7

我在我的文本框有一个ExceptionValidationRuleExceptionValidationRule没有反应异常

<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模式下,一切工作正常。

有人可以告诉我,为什么地狱这是怎么回事?我该如何解决这个问题?

+0

您是否附加了UnhandledException事件? – Krimson 2010-12-08 14:09:44

回答

8

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

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

+0

非常感谢你。由于同样的问题,我一直在嘲笑我。非常感谢 – Shee 2012-08-24 08:46:08

+0

然后会发生什么异常被触发,WPF *不会*优雅地捕捉它。调试器仍然工作吗? – 2014-03-28 10:16:46