I have a form with TextBox that holds Age. I have implemented validation like this:
In my ViewModel, I have property age:
private float age;
public float Age {
get { return age; }
set
{
if (value <= 0 || value > 120)
{
throw new ArgumentException("The age must be between 0 and 120 years");
}
age= value;
}
}
My XAML is:
<TextBox Name="txtAge" Text="{Binding Age, UpdateSourceTrigger=PropertyChanged, StringFormat=N1, ValidatesOnExceptions=True}" />
This all works fine and if I enter age 300, I get error showing under my text box. But how do I disable the button in case an error occurs?