gpt4 book ai didi

wpf - ExceptionValidationRule 不对异常使用react

转载 作者:行者123 更新时间:2023-12-04 11:45:10 25 4
gpt4 key购买 nike

我有一个 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 绑定(bind)引擎没有捕捉到这一点,我认为它应该......)。

RELEASE模式,一切正常。

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

最佳答案

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

在“调试”菜单中,选择“异常(exception)...”。在此对话框中,您可以控制 VS 如何处理异常。简单 取消选中“用户未处理”对于“Common Language Runtime Exceptions”,按 OK 并再次运行您的项目。

关于wpf - ExceptionValidationRule 不对异常使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com