Reputation: 1
I trying to display validation error messages as summary in wpf. Right now I'm able to display it as tooltip for each control using ErrorProvider.
My requirement is that I should display validation error messages of all controls in one place as a summary.
Please let me know how it can be done.
Thanks, Vinutha
Upvotes: 0
Views: 1785
Reputation: 6690
You are definitely going to need a sample project here.
What I do is create a StackPanel with a TextBlock for each TextBox you need to have filled out. Then you bind to the Validation of the element.
Here is a sample project I made when needed to do almost exactly what you are asking. I tracked it down and through it up on my blog for you.
TextBox Validation – How to bind properties of the Validation of a TextBox?
Upvotes: 1
Reputation: 38373
What I do is store all the error messages in a dictionary, indexed by property name, this is where I read from in the IDataErrorInfo indexer. This dictionary is populated via validation code.
You could also create an ObservableCollection where you populate any error messages from the values in the dictionary and bind this to an ItemsControl on your UI. Or implement an ObservableDictionary to store your error messages.
Previously I have used a message box to display this collection of errors when the user presses save, for example.
Upvotes: 1