When I first display my screen to the user, I'd rather not have all the validation messages show up for required fields and such before the user has had a chance to fill in any of the form fields. I've set the UpdateSourceTrigger
on my bindings to LostFocus
, but the errors are still displayed the first time the control is shown. Is there any way to get around this?
XAML:
<TextBox Text="{Binding Path=OpeningOdometer, ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" />
ViewModel:
[Required(ErrorMessage = "Please enter the opening odometer.")]
[Range(0, Double.MaxValue, ErrorMessage = "Opening Odometer must be a positive number")]
public string OpeningOdometer
{
get { return _openingOdometer; }
set
{
_openingOdometer = value;
NotifyOfPropertyChange(() => OpeningOdometer);
}
}
// Implementation of IDataErrorInfo
public string this[string columnName]
{
get
{
// This uses the System.ComponentModel.DataAnnotations placed on
// the OpeningOdometer property to produce an error string
// if the value of the property is in violation of any of the
// annotated rules.
return _valHelper.GetErrorsForProperty(columnName, this);
}
}