I have a class in my SL4 app that represents a single entity the user is inputing data about. I am doing data validation as follows:
private double cost;
public string Cost
{
get
{
return String.Format("{0}{1}", DOLLAR_SYMBOL, cost);
}
set
{
string price = getPriceFromCost(value);
if (!double.TryParse(price, out cost))
{
throw new ArgumentException("Please enter a number.");
}
OnPropertyChanged("Cost");
}
}
This works great. However, if the user enters a valid value, then an invalid one, ignores the validation error, and hits submit, the entity will be created with the old valid value. I would rather force the user to correct the error. How can I disable the "Add" button?
Also, I would like to do some other forms of validation when the user clicks the add button, but I still want the nice effect of the text input box being highlighted in red, with the message that pops out. How can I do this without throwing ArgumentExceptions
?