Wednesday, February 15, 2012

Handling Text box for only positive Integers No and showing error message in silverlight Using MVVM

Following is the property that can be bind to text box, and handles the text box to enter only integer values, and converting to positive Integer value if any negative Integer value will entered in text box.



private String strPageSize = "";

public String PageSize
{
 get { return strPageSize; 
 set
    {

     Regex myRange = new Regex(@"^-{0,1}\d+$");
     if (!myRange.IsMatch(value))
     {
       throw new Exception("Numbers are allowed only");
     }
     strPageSize = (Math.Abs(Convert.ToDecimal(value))).ToString();
     RaisePropertyChanged("PageSize");
     }
}

No comments:

Post a Comment