当我第一次向用户展示屏幕时,我希望在用户填写表单字段之前不要显示所有必填字段和其他验证消息。 我已将绑定的
XAML:
UpdateSourceTrigger
设置为 LostFocus
,但是第一次显示控件时仍会显示错误。 有没有办法解决这个问题?XAML:
<TextBox Text="{Binding Path=OpeningOdometer, ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" />
视图模型:
[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);
}
}