Search code examples
c#wpfvalidationxamlidataerrorinfo

IDataErrorInfo Interface, Bubble up the Validation.HasError message


I have implemented validation of a usercontrol using IDataErrorInfo interface. Now, I am using this userControl inside a Parent UserControl. In the Parent UserControl, i have a Save Button. I want to bind this parent's Save Button to the Clild UserControl's Validation.HasError property.

What would be the best way to implement this. I actually have 3 such usercontrols in the parent userControl . And I want to OR the Validation.HasError property of each of these child usercontrols


Solution

  • You could listen to Validation.Error event inside the UserControl which holds the Save Button. When in handler you will be able to find out if new error was added or was removed. Futhermore you will able to find out what is the actual error message or how many error messages are there since like you mentioned technically you could have more than just one error. I guess you know how to do the rest...

    Since its a UserControl you will able create the handler for that event in code behind and you will be able to access the save button by name in order to change it enable state.