I have a window with 8 rows representing 8 output channels, in each channel I can have timesteps. So I have a textbox in front of each channel to set the upper and lower limit for the value of the timesteps. What I now want to do is to write a validator which checks the user input if it's inside of those limits. I'm not sure how to do this, because when the validator is invoked it has no knowledge about which timestep in which channel it's called from and I see no possibility to pass extra information to the validator.
Edit:
public class NumberValidator : ValidationRule
{
public override ValidationResult Validate (object value, System.Globalization.CultureInfo cultureInfo)
{
double number = 0;
try
{
number = Convert.ToDouble(value.ToString()); // Check for numeric value
}
catch (Exception)
{
return new ValidationResult(false, "Value must be numeric");
}
if (number == 0) // Check for non-zero value
{
return new ValidationResult(false, "Value must be non-zero");
}
return new ValidationResult(true, null);
}
}
This is how you use validator normally, you compare your input to some constant value. My problem is that instead of comparing number being equal to zero. I want to compare number to an attribute of another object, but I'm not sure how to pass this other object into the validator.