我在數據表單中有一個dataform和一個datagrid。這個數據網格綁定到一個ObservableCollection。我寫了一個CustomValidator,當可觀察集合中的計數爲0時拋出ValidationException。ValidationSummary控件不處理此異常,而是應用程序變得不穩定並調用Application Unhandled Exception。我沒有使用RIA服務。以下是我的代碼Silverlight驗證摘要不處理ValidationException
public class UserCompanyProgram : INotifyPropertyChanged
{
public void ToWebServiceProgram()
{
lstUserProgram.CollectionChanged += (sender, e) =>
{
//Validator.ValidateProperty(lstUserProgram,
// new ValidationContext(this, null, null) { MemberName = "lstUserProgram" });
lstUserProgram = _lstUserProgram;
UserProgramChanged();
};
}
private ObservableCollection<Pricing.Model.UserProgram> _lstUserProgram = new ObservableCollection<UserProgram>();
[CustomValidation(typeof(ModelValidator), "ValidateUserProgramCollection")]
[Display(Name = "New Programs", Description = "Add program")]
public ObservableCollection<UserProgram> lstUserProgram
{
get { return _lstUserProgram; }
set
{
Validator.ValidateProperty(lstUserProgram,
new ValidationContext(this, null, null) { MemberName = "lstUserProgram" });
this._lstUserProgram = value;
NotifyPropertyChanged("lstUserProgram");
}
}
}
dgSelectedPrograms.SetBinding(DataGrid.ItemsSourceProperty, new Binding("lstUserProgram") { ValidatesOnNotifyDataErrors=true, ValidatesOnExceptions=true });
如何使ValidationSummary句柄成爲異常?