Search This Blog

Tuesday, October 11, 2011

Silverlight CustomValidation attribute; ValidationResult.MemberNames.Count == 0

When writing CustomValidation remember to include memberNames in ValidationResult. ValidationResult.MemberNames include property names which are validated at a given moment (are connected to the validation result which we received).

Sample validation should look like the following:

public class CustomValidationMethods
    public static ValidationResult SthNumberValidation(string name, ValidationContext validationContext)
        string[] memberNames = new string[] { validationContext.MemberName };

        if (name.StartsWith("B"))
            return ValidationResult.Success;
            return new ValidationResult("Name does not begin with 'B'", memberNames);

No comments:

Post a Comment

If you like this post, please leave a comment :)