binding validation
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace BindingValidationRuleSample.Validation
|
||||
{
|
||||
public class AgeRangeException : ValidationRule
|
||||
{
|
||||
public int MinAge { get; set; } = 0;
|
||||
public int MaxAge { get; set; } = 150;
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
int age = 0;
|
||||
if (!int.TryParse(value.ToString(), out age))
|
||||
return new ValidationResult(false, "Wrong value.");
|
||||
|
||||
if (age >= this.MinAge && age <= this.MaxAge)
|
||||
return new ValidationResult(true, null);
|
||||
else
|
||||
return new ValidationResult(false, $"Valid age range is {this.MinAge}~{this.MaxAge}");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user