Validation Markup for custom DataAnnotation on Entity

Apr 19, 2012 at 6:48 PM

Hello, 

I have custom data annotation attribute which is applied to whole class (not to single property). Could anybody please point me how to show it in markup (XAML) (BookLibrary example seems not working because annotations are applied to a property)

Thanks in advance,

Mikhail

Coordinator
Apr 21, 2012 at 7:38 PM
Edited Apr 21, 2012 at 7:40 PM

The BookLibrary example uses the DataErrorInfoSupport class for supporting the DataAnnotation validation. It validates only the Property attributes. You could rewrite this class to validate the object validation attributes as well.

// Validates only property attributes
Validator.TryValidateProperty(property.GetValue(instance), 
    new ValidationContext(instance, null, null) 
        { MemberName = memberName }, validationResults);

Note: This might have some performance impact.