Hello!
I am validating a class with DataAnnotations
utils.
I have a class that has a Title
property and an Item
property.
I want to apply a RequiredAttribute
to the Title
property but it should be invalid only if the Item
property is null; if the Item
property is set with an object, the Title
is not required.
In short words, I want the RequiredAttribute
to validate only if a condition in the class is satisfied.
How can this be done.
Update
As I didn't find other way, and since I usually don't need this functionality so often, I decided to make it the rough way using a class-level validator. my question is then, is there a way to manually update the UI to make that Title TextBox with a red frame, i.e. to invalidate it?
Update 2
I want the class-level validator to summarize on a field.
For example, I have to fields Cost and SalesPrice, I wanna make sure that SalesPrice > Cost and invalidate the SalesPrice otherwise, I don't want a global validation error on the class level.
I prefer to do it the xamly way.