This question seems very similar to the previous one , but the case is a little different (perhaps it better demonstrates the problem), although the goal is the same.
XAML:
<TextBox Text="{local:ExceptionBinding Path=Color1}" />
CS:
public class ExceptionBinding : Binding { public ExceptionBinding() { ValidationRules.Add(new ExceptionValidationRule()); } }
ut:
Color _color1; public string Color1 { get { return (new ColorConverter()).ConvertToString(_color1); } set { _color1 = (Color)ColorConverter.ConvertFromString(value); } }
When this code works offline, for input 123 a red frame is displayed around the TextBox (the value of the field does not change). Entering red or #FF0000 will remove the boundary and update field value.
Problem: when starting the program in Visual Studio, 123 input will be issued when ConvertFromString ( undocumented btw):
An exception of type "System.FormatException" occurred in PresentationCore.dll, but was not processed in user code
Additional information: the token is invalid.
How to prevent Visual Studio from interrupting program execution?
source share