System. Windows. shapes;
UsingSystem. componentmodel;
Namespace Wpfapplication1
{
/// <Summary>
/// Interaction logic of window1.xaml
/// </Summary>
Public Partial Class Window1: Window
{
Public Person;
Public Window1 ()
{
Initializecomponent ();
// Create and bind sample data
Person = New Person ();
Person. Name = " Kill " ;
Person. Age = 21 ;
This . Txtage. datacontext = Person;
}
}
// the data class must inherit inotifypropertychanged
Public class person: inotifypropertychanged
{< br> Public event propertychangedeventhandler propertychanged;
string name;
Public string name
{< br> Get { return name ;}
set {name = value ;}
}
int age;
Public int age
{< br> Get { return age ;}
set {age = value ;}
}
PublicPerson (){}
}
// Write the Judgment Rule class inheriting validationrule
// Rewrite the validate method to complete your judgment.
Public Class Numberrangerule: validationrule
{
Int Min;
Public Int Min
{
Get { Return Min ;}
Set {Min = Value ;}
}
int MAX;
Public int max
{< br> Get { return MAX ;}
set {max = value ;}
}
Public Override Validationresult validate ( Object Value, system. Globalization. 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 ( " Number out of range ({0}-{1 }) " , Min, max ));
}
ReturnValidationresult. validresult;
}
}
}