I'm using validationrule class to validate my textbox values against length. It works fine and show the error also if it is invalid but the problem is if users are editing the textbox it is not storing the value and does not even call set.
I want to have the the values whatever user is entering in textbox even if it is valid or not. Is there a way to get through this.
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
string valueToValidate = value as string;
if ((MinLength > 0 || MaxLength >0) && (valueToValidate.Length < MinLength || valueToValidate.Length > MaxLength))
{
return new ValidationResult(false, $"The field lentgh should be between: {MinLength}-{MaxLength} characters.");
}
else if(APIKeyLength>0 &&(valueToValidate.Length != APIKeyLength))
return new ValidationResult(false, $"The field lentgh should be 36 characters");
return new ValidationResult(true, null);
}
And in xml it is like:
<Binding Path="ClientID" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<advancedConfigurationPage:ClientIDValidationRule MinLength="8" MaxLength="100"/>
</Binding.ValidationRules>
Setting the ValidationStep
property of the ValidationRule
to UpdatedValue
will cause it to run after the source property has been set;
<advancedConfigurationPage:ClientIDValidationRule MinLength="8" MaxLength="100"
ValidationStep="UpdatedValue" />