I am using modern UI. I didn't implement IDataErrorInfo at my view model base or any view model, and yet, I get validation error. Namely, when I type in a value in a text box then remove it, I get the error: value '' could not be converted. Also, when I put a break point on the property, I find it holding on to the old value. Thanks
1 Answers
guess: the Type of that property is something non-nullable, like int
or double
or Color
without ?/Nullable
modifier. The Binding expression used to bind the control binds directly to the datastructure and lacks a smart converter and lacks a fallback value, so it totally fails to convert an empty string. The UI framework detects the problem and reports the error.
IDataErrorInfo may need to be implemented if you need more complex validations, but that does not mean that no validation and no conversion happens when you don't implement it. Bindings still may fail, as some converter may i.e. throw or return a value of wrong type. Run the app in debug mode and observer Output panel. I bet you will see some reports about failing bindings operations.

- 32,194
- 8
- 68
- 107
-
No, My property is nullable. deciaml? – Talal Yousif Jan 11 '15 at 13:20
-
Hm.. ok, thats totally strange. For now, I'm out of guesses. You will probably need to drop some code depicting your XAML with bindings and the underlying datastructures (the one that's being boudn to UI). – quetzalcoatl Jan 11 '15 at 13:28
-
in the binding, I Added , `TargetNullValue=''` and it worked. [This is the question](http://stackoverflow.com/questions/1895453/set-value-to-null-in-wpf-binding) – Talal Yousif Jan 12 '15 at 06:31