I have a complicated scenario using ValidationRules that I need some help with. I have a User Control that is roughly organized like this:
Parent (ItemsControl)
Child 1
Property 1
Property 2
Child 2
Property 1
Property 2
When Child 1.Property 1 is changed, I need to perform validation on it. However, the validation rule requires the value of Child 1.Property 1 as well as the Property 1 values for all its siblings (variable number) to perform the validation. I could put a ValidationRule on the Parent ItemsControl, but I need the Control bound to Child1.Property1 to show the error. Currently when I place the validation on the parent the error is displayed on the parent, not the child. I've also considered using BindingGroups but I want the validation to fire automatically when a property is changed. There isn't, to my knowledge, a way to automatically force Validation to fire for a BindingGroup.
Is there a way to accomplish what I am trying to do?
This automatically turns all the object's data annotation attributes into
ValidationRules, and can be applied once in the app on allTextBoxes:Usage:
I made the
DaValidationRuleclass abstract because I think I might want to expand that in the future so it also coversIValidationAttributeand maybe other scenarios.For the version that covers
TextBoxes withinDataGridTextColumnin edit mode, and for full code, see this.