25 lines
789 B
C#
25 lines
789 B
C#
using System.Windows.Controls;
|
|
|
|
namespace JD.WPF.Validation
|
|
{
|
|
public class PositiveFloatValidationRule : FloatValidationRule
|
|
{
|
|
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
|
|
{
|
|
// Value must be string or float
|
|
float floatValue;
|
|
ValidationResult result = ParseValue(value, out floatValue);
|
|
if (!result.IsValid)
|
|
return result;
|
|
|
|
result = base.Validate(floatValue, cultureInfo);
|
|
if (!result.IsValid)
|
|
return result;
|
|
|
|
if (floatValue < 0.0f)
|
|
return new ValidationResult(false, "Negative values are not allowed");
|
|
|
|
return new ValidationResult(true, "");
|
|
}
|
|
}
|
|
}
|