I have a working WPF dialog that uses DataGrid. The DataGrid is set to have ItemsSource={Binding SomeCollection, Mode=TwoWay}. This setup works fine, I can read values and update them from UI.
Later I have added Converters to validate values. I show blank when validation fails. Now I am interested in getting the original values back in case if validation fails.
What options do i have here?
I have never used a converter for validation. Instead I use items that implement IDataErrorInfo with an attribute in the databinding attribute for ValidatesOnDataErrors=True.
Using this method of validation, the original value is retained, and the object returns the errors value (in my case a string saying what the error is). My View’s controls have a custom validation item which adds a red border which fades over time, and a tooltip that pops up on mouse hover.
Then you just need to put your validation rules in the data classes you are displaying:
Edit
And just for the heck of it, I will put an example validation template in to show others how to hook it up.
Finally:
A MSDN article on implementing Validation
A video to go with it. Video number 4