mvvmgen icon indicating copy to clipboard operation
mvvmgen copied to clipboard

Input Validation with INotifyDataErrorInfo

Open thomasclaudiushuber opened this issue 3 years ago • 3 comments

MvvmGen should support an easy way to implement input validation with the INotifyDataErrorInfo interface.

  • A ValidationViewModelBase class is something that could make sense.
  • A partial method that users could implement to return validation errors would also be great.
  • Also check if there is an easy way to integrate this with common validation patterns, like Data Annotations and FluentValidation

Note: This issue might make sense when WinUI gets its input validation done: https://github.com/microsoft/microsoft-ui-xaml/issues/179

thomasclaudiushuber avatar May 21 '21 05:05 thomasclaudiushuber

+1 for this proposal

I am facing InputValidation right now in WPF when using mvvmgen and wondering about why this feature isn't part of mvvmgen.

But i also read your discussion on ms-ui-xaml post and understand why you are not implementing this feature before ms implement the framework for this in win ui.

In the meantime. Do you have a suggestion for inputValidation in WPF in 2022?

Daimonion1980 avatar Sep 30 '22 10:09 Daimonion1980

Hey @Daimonion1980 ,

yes, exactly, WinUI is the reason it's not here yet, but seems that the WinUI team is not making much progress on this one.

The approach for WPF is to implement INotifyPropertyChanged for input validation.

With mvvmgen, you could create a ValidationViewModelBase class that inherits from MvvmGen's ViewModelBase class. Then you implement the INotifyPropertyChanged interface on ValidationViewModelBase and you inherit your ViewModels that require validation from that new ValidationViewModelBase. To do that, you usually override the OnPropertyChanged method and from there you call a Validate method to add or remove errors per property (that you have to store in a dictionary).

Maybe I should create a simple example for this.

thomasclaudiushuber avatar Sep 30 '22 11:09 thomasclaudiushuber

Thank you for your input.

An Example would be great. ;)

Daimonion1980 avatar Sep 30 '22 11:09 Daimonion1980