You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace SiaSun.LMS.WPFClient.UC.Validate
|
|
{
|
|
/// <summary>
|
|
/// 数值范围验证
|
|
/// </summary>
|
|
public class ValidateNumberRangeRule : ValidationRule
|
|
{
|
|
int min;
|
|
public int Min
|
|
{
|
|
get { return min; }
|
|
set { min = value; }
|
|
}
|
|
|
|
int max;
|
|
public int Max
|
|
{
|
|
get { return max; }
|
|
set { max = value; }
|
|
}
|
|
|
|
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
|
|
{
|
|
int number;
|
|
if (!int.TryParse((string)value, out number))
|
|
{
|
|
return new ValidationResult(false, "Invalid number format");
|
|
}
|
|
|
|
if (number < min || number > max)
|
|
{
|
|
return new ValidationResult(false, string.Format("输入值超出范围:({0} - {1})", min, max));
|
|
}
|
|
|
|
return ValidationResult.ValidResult;
|
|
}
|
|
}
|
|
}
|
|
|