Getting Control level (view) validation errors back to the View Model

Go To StackoverFlow.com

0

I've got a custom control that gets bound to an object from view model. The control has its own "mini viewmodel"(implements raisedproperychanged and idataerrorinfo) it its code behind for some specific validation.

There are some properties used internal to this control that can cause the control to be in an invalid state (these properties are inherent to the control, and do not represent properties of the model we are bound to). How can I get these validation errors to "bubble up" so that the property that is bound to this control shows as having a validation error?

For a more clear example. Say I have a person object that I bind to the person property of the custom usercontrol. This control will allow you to edit the sub properties and such of the person. There is additional validation in this control beyond what is normally applied to a person object, such as the control being "invalid" until the user closes a dialog that the control created, or clicked a checkbox indicating they were finished editing. I want these validation errors to propagate out so that the binding to the person property shows the validation error, or more specifically, the VM that contains it.

2012-04-04 20:09
by Brandorf


1

You've got it the wrong way around - the control sets the value on the ViewModel (through binding) and the ViewModel validates each field and provides an error message through IDataErrorInfo. For more information see: http://codeblitz.wordpress.com/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/

2012-04-04 20:15
by Slugart
I'm aware of how IDataErrorInfo works, I'm looking for a way to indicate that "Person" itself is invalid, not just person's sub-properties - Brandorf 2012-04-04 20:20
While it doesn't solve my immediate problem, I'm going to mark this as the answer, as it seems my real problem is the approach, not the lack of an interface to do what I want. ; - Brandorf 2012-04-16 21:32
Ads