Why only 1 BusinessRule Error and Warning allowed?

Feb 5, 2012 at 2:08 AM

I just discovered that the WarningAndErrorValidator only stores a maximum of one BusinessRule Error and one BusinessRule Warning.  Looking at the source code for WarningAndErrorValidator, and specifically the CheckObjectValidation method, this appears to be by design.  In my opinion, this restriction shouldn't exist - there are certainly scenarios where there can be more than one business error and/or warning. 

For example, I discovered this while creating a window that has several comboboxes, all with the same ItemsSource.  In most cases, it doesn't make sense for the user to set two comboboxes to the same value, but it isn't disallowed.  So, when the user does this, I want to display a warning that says something like, "Field A and Field B are set to the same value."  If there are two sets of matching fields, there should be a warning for each.  I am sure I can work around this by treating this as a Field Warning instead, but logically, it makes more sense to me for this to be a BusinessRule Warning since it deals with multiple fields. 

Feb 5, 2012 at 9:54 AM

Completely agree with you. We see no reason why the people at Microsoft only added 1 Message property to the IDataErrorInfo. We though about several ways to bypass this limitiation such as listing all the errors inside the Message property. However, then you cannot have any control about how the messages are formatted (so you cannot show them in a list).

So, what we came up with is the ValidationContext (and ValidationSummary). It allows you to query all errors and warnings the way you like of an object. By default, the DataObjectBase (for models) and the ViewModelBase provide the ValidationContext so you can query all info.

However, the InfoBarMessageControl and WarningAndErrorValidator do not yet use this class. I think it is a good idea to introduce this so I created a task for this. You can subscribe to it to follow its progress.


Feb 5, 2012 at 1:48 PM

Thanks, Geert.  Makes sense.