Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually it is do able just not the way you think you want it to occur. The below would be the steps I would follow to do something similar.</p> <ol> <li>get the Microsoft enterprise library for starters as you will be using the <code>Microsoft.Practices.EnterpriseLibrary.Validation</code> reference.</li> <li>Create a validation class that inherits from <code>Validator&lt;T&gt;</code> (this is part of the Enterprise library).</li> <li>Override the method <code>DoValidate(T objectToValidate, object currentTarget, string key, ValidationResults validationResults)</code> and currentTarget is the object being validated. You can pull the validation rules from the current target.</li> <li>You then create attribute for that validate making it inherit from <code>ValueValidatorAttribute</code>.</li> <li>You override the method <code>DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory)</code> in the attribute class.</li> </ol> <p>Once these first 5 steps are done it means you can attribute properties you want to validate and let the validator pick up the validation rule to use from the class (list of rules or dictionary or rules to perform to the property totally your choice).</p> <p>The next step is to move the interface <code>IDataErrorinfo</code> to the parent class, create a <code>Validate()</code> method that takes the results from the call <code>Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate(this);</code> which returns validation errors should they have occurred. </p> <p>Its up to you on how where you want to place the method call. The simplest way when testing would be to place it in the <code>OnPropertyChanged</code> method you have.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload