내 모델이 INotifyDataErrorInfo
인터페이스를 구현하여 해당 속성의 유효성을 검사하고 정상적으로 작동하지만 문제는 HasErrors 속성이 기본적으로 false이므로 처음으로 앱을 실행하고 저장을 클릭합니다. (양식이 비어 있음) 뷰가 오류를 발생시키지 않고 데이터가 저장됩니다. 여기 INotifyDataErrorInfo를 사용하여 Mvvm 모델 유효성 검사
public LoggingViewModel()
{
_loggingCommand = new RelayCommand(checkCredentials, canExecuteLogginForm);
_logingModel = new LoggingModel();
// I raise this event in the 'OnErrorsChanged' method in the model,
// so my ViewModel can subscribe and check the 'HasErrors' property.
_logingModel.FormIsValid += (o, e) => _loggingCommand.RaiseCanExecuteChanged();
}
private bool canExecuteLogginForm()
{
return !_logingModel.HasErrors;
}
의 snipet 어떻게 앱이 상황을 처리 할 것입니다?
자세한 내용은이 github repos를 만들었습니다.
기본적으로 HasErrors가 참이므로 코드를 업데이트 할 수 있습니까? LogginModel 생성자에서 유효성 검사 또는 유효성 검사를 수행 하시겠습니까? – robaudas
HasErrors는 INotifyDataErrorInfo 인터페이스의 멤버이며 폼에 오류가 없으면 false를 반환해야합니다. 검증을 어떻게 강제 할 수 있습니까? –