Sin*_*atr 5 c# debugging wpf exception mvvm
这个问题看起来与之前的问题非常相似,但案例有点不同(可能更好地展示了问题),尽管目标是相同的.
XAML:
<TextBox Text="{local:ExceptionBinding Path=Color1}" />
Run Code Online (Sandbox Code Playgroud)
CS:
public class ExceptionBinding : Binding
{
public ExceptionBinding()
{
ValidationRules.Add(new ExceptionValidationRule());
}
}
Run Code Online (Sandbox Code Playgroud)
VM:
Color _color1;
public string Color1
{
get { return (new ColorConverter()).ConvertToString(_color1); }
set { _color1 = (Color)ColorConverter.ConvertFromString(value); }
}
Run Code Online (Sandbox Code Playgroud)
当此代码独立运行时,显示输入123红色边框TextBox(字段值不变).输入red或#FF0000将删除边框并更新字段值.
问题:在Visual Studio下运行程序时,输入123将抛出ConvertFromString(未记录的顺便说一句):
PresentationCore.dll中出现"System.FormatException"类型的异常,但未在用户代码中处理
附加信息:令牌无效.
如何防止Visual Studio中断程序执行?
CTRL您可以通过按“ + D+ E”或点击“调试”菜单、Windows 和异常设置来选择 Visual Studio 中断的异常(有关详细信息,请参阅 MSDN:https: //msdn.microsoft.com/en-us/library/x85tt0dd .aspx )
然后取消选中您不想看到的异常(对于转换器,只需取消选中 CLR 异常)
之后,只需注意输出窗口中的此类异常...
| 归档时间: |
|
| 查看次数: |
338 次 |
| 最近记录: |