I have a textbox in a WPF application bound to a property on a Linq to Entities class that implements IDataErrorInfo. The textbox binding has ValidatesOnExceptions=True and ValidatesOnDataErrors=True. When the textbox is bound to an integer property and the user enters text then the textbox outline displays as red as I haven’t set up a custom style.
In my Save method how do I know the object can’t be saved as it’s invalid? I’d prefer the user clicks the Save button and I can notify them of a problem rather than disabling the Save button.
Cheers,
Dave
I haven’t found an easy way to do it. I found some code around the traps to recurse through all the controls on the form and determine if any of them have validation errors. I ended up turning it into an extension method:
So then when the user clicks the Save button on a form, I do this:
It’s a lot more work than it should be, but using the extension method simplifies it a bit.