This question seems very similar to previous, but the case is a bit different (perhaps better demonstrating the problem), though goal is the same.
xaml:
<TextBox Text="{local:ExceptionBinding Path=Color1}" />
cs:
public class ExceptionBinding : Binding
{
public ExceptionBinding()
{
ValidationRules.Add(new ExceptionValidationRule());
}
}
vm:
Color _color1;
public string Color1
{
get { return (new ColorConverter()).ConvertToString(_color1); }
set { _color1 = (Color)ColorConverter.ConvertFromString(value); }
}
When this code runs standalone, for input 123 red border is shown around TextBox (field value is not changing). Entering red or #FF0000 will remove border and update field value.
Problem: when running program under Visual Studio, entering 123 will throw at ConvertFromString (undocumented btw):
An exception of type 'System.FormatException' occurred in PresentationCore.dll but was not handled in user code
Additional information: Token is not valid.
How to prevent Visual Studio from interrupting program execution?