Hello search engine visitor. You may be feeling underwhelmed by the other answers to this question. There are two correct answers, depending on exactly what you mean by "all errors":
All binding errors within the current control
If you have multiple bindings to properties which may produce binding validation errors, the correct way to gather them together is to add a BindingGroup
to your control. You can then query this object for all of the errors produced by the bindings it knows of. I won't go into detail about how to set this up; check Microsoft's documentation.
All INotifyDataErrorInfo
errors in the data object
Perhaps you don't actually have any bindings to individual properties, because (for example) you are displaying an error message in a prompt and need to list all of the reasons why the user can't proceed.
You can abuse the GetErrors
method to return all known errors when a null/empty string is passed, but this is a hack. You could also add a new property which returns all errors, but this means changing your data model and adding bespoke handling for the errors changing.
I have a better solution for you: DataErrorsControl
. This is a custom control which:
- Queries all properties of the
ErrorSource
object and flattens the resulting errors (with the help of CompositeCollection
), then exposes that collection in read-only form as a CollectionView
- Has an
IsExpanded
property which determines whether it displays all of the errors as a list, or just one error at a time on a single line
- Supports asynchronous error generation, as required by the
INotifyDataErrorInfo
interface
Enjoy!
P.S. I also added support for navigating back/forward through the errors, but left the required buttons out of the default template to keep it simpler. You can add the UI or remove the command handlers per your requirements.