I found a solution.
I was hoping to do it with validation through Events, but i was wrong.
Suffice it to implement the INotifyDataError and use CustomValidadionAttribute.
(example: https://anthymecaillard.wordpress.com/2012/03/26/wpf-4-5-validation-asynchrone/)
Medot will look something like this
public static ValidationResult CustomValidate(object obj, ValidationContext context)
{
var itemObject = (ItemModel)context.ObjectInstance;
if (itemObject .Type == ItemType.Type1
&& !itemObject .Property1.HasValue)
{
return new ValidationResult(string.Format("Mandatory for type '{0}'", itemObject .Type .GetDescription()), new List<string> { "Property1" });
}
if (itemObject .Type != ItemType.Type1
&& itemObject .Property1.HasValue)
{
return new ValidationResult(string.Format("Not allowed for type '{0}'", itemObject .Type .GetDescription()), new List<string> { "Property1" });
}
return ValidationResult.Success;
}
Thanks for your reply.
I have read the documentation before.
I was interested in revalidation of some fields by another field value changes.
And I was able to get it to implement INotifyDataErrorInfo.
But now I got another error. Could you help me with it?
I call revalidation for all properties in OnPropertyChanged, so i can be sure that all properties of model update error state. But the validation error in messages hint duplicated. Apparently, one takes by grid, the other is sent by property changed.
But with GridTemplateColumn it works fine, as with all other controls in which there is bounded to a properties with validation .
Is it possible to avoid duplication without replace column by GridTemplateColumn with standart controls in template?
And maybe i should create a separate topic for this issue?