Implementing INotifyDataErrorInfo (View Model Data Validation) - EASY WPF (.NET CORE)

  Рет қаралды 18,474

SingletonSean

SingletonSean

3 жыл бұрын

Learn how to implement INotifyDataErrorInfo to perform data validation on view model properties. Validating data in the view model (rather than the view) is useful for keeping the UI simple and promoting validation reusability and testability.
SOURCE CONTROL: github.com/SingletonSean/wpf-...

Пікірлер: 35
@RamonWilliams
@RamonWilliams 3 жыл бұрын
I can't quite express how big of a help these videos are Sean. You have a great way of explaining things. Thank you very much!!!
@bullet4255
@bullet4255 2 жыл бұрын
Concise and helpful, great job!
@longuinni
@longuinni 3 жыл бұрын
Awesome tutorial!!! Finally one tutorial that explains the right way. Thanks Sean. Another suggestion is how to animate controls with storyboard.
@SingletonSean
@SingletonSean 3 жыл бұрын
Thanks Fernando! Happy to hear this satisfied your INotifyDataErrorInfo request from earlier. I've touched on storyboard animations a bit in my Custom Controls playlist, but it would certainly be useful to dedicate a video to the topic. Great suggestion.
@islamabdel-fatah5210
@islamabdel-fatah5210 2 жыл бұрын
Excellent work , thank you very much !
@robbienorton9522
@robbienorton9522 2 жыл бұрын
Another Great WPF Tutotrial. This one I didn't have trouble follow your speed or have to slow the tutorial down. I do have to say it seems kind of a hokey way to not use inheritance or a viewmodelbase with error handling built in, but that's just me. Keep up the excellent work !! =)
@dhruvsinha3907
@dhruvsinha3907 2 жыл бұрын
Awesome tutorial !! Thank you
@amryakout2957
@amryakout2957 Жыл бұрын
Great work 👏
@user-ub7ud7th3v
@user-ub7ud7th3v 3 жыл бұрын
Thank you. The information about ErrorTamplate is very helpful to me. When I was choosing ways to implement INotifyDataErrorInfo, I ended up using Fody Validar + FluentValidation. And even if you don't want to use Fody, you can still use their INotifyDataErrorInfo example implementation: github.com/Fody/Validar#fluentvalidation Call it in the constructor like _validationTemplate = new ValidationTemplate(this);
@andreac1293
@andreac1293 2 жыл бұрын
Thank you. Very useful tutorial. Just a question: How can I show only the first element of the errorContent in the adorner? On google I found this Text="{Binding [0].ErrorContent}" but it seems not working.
@piotrgoacki9070
@piotrgoacki9070 2 жыл бұрын
How do you use it with the DataGrid? it seems that it doesn't really work well with the DataGrid?
@mattc4153
@mattc4153 Жыл бұрын
Nice work you know WPF well. Any chance you would be available for hire for a few hours for some Q&A? Thanks!
@X3.notcom
@X3.notcom 5 ай бұрын
Hi! Great tutorial! Wery helpful, but I can`t find unsubcribe "_errorsViewModel.ErrorsChanged -= ErrorsViewModel_ErrorsChanged;" in video
@hariprasadc8332
@hariprasadc8332 Жыл бұрын
Hi I am using INotifyDataErrorInfo in a user control and it validates if a textbox is null or empty. I have created an event in a interface invoked that event when there is any validation errors. I subscribed this event in another project by loading the dll of the above usercontrol and tried to subscribe to the event. But the event was not getting triggered in this project. I want to display the number of errors in the usercontrol and show the number of errors when the user clicks on next button.
@hariprasadc8332
@hariprasadc8332 Жыл бұрын
I also want a placeholder in the textbox, so if I use stackpanel for the template its not working. And If I use Grid the error msg is comming inside the textbox. Is there any way to solve this issue?
@alanv.174
@alanv.174 3 жыл бұрын
Really great video and explanation, I just have one problem with it. If the user were to skip a mandatory field entirely there would be no error as the setter of the field wouldn't be called. Do you have a clean solution for this?
@SingletonSean
@SingletonSean 3 жыл бұрын
Thanks Alan! Ironically, I've been doing a lot with forms lately. My approach has been to re-evaluate all of the validation when the user clicks the submit button. Here's a live example (not written by me): eo6en.csb.app/
@alanv.174
@alanv.174 3 жыл бұрын
@@SingletonSean Thank you! I'll be sure to check out the example. I ended up putting the validation in a method which also gets called when you press the button as temp solution. Cheers for all the informative content. Keep it up !
@siavash2176
@siavash2176 3 жыл бұрын
I wish there was a quick way without doing all this repetitive code on all projects, I hope with C# source generator this stuff get better, same for PropertyChanged, you have to have fields for each property and raise the property changed event, I use Prism and it makes it much easier but if there was a way to do it with an attribute it would be much better, anyway the video was great and very helpful like always, thanks!
@SingletonSean
@SingletonSean 3 жыл бұрын
I agree Siavash. It is definitely repetitive to scaffold out all of these interface implementations, such as INotifyPropertyChanged and INotifyDataErrorInfo. Luckily those libraries ease the pain a bit, haha.
@jadenschulz1004
@jadenschulz1004 6 ай бұрын
Data validation in wpf feels bad... so many edge cases, I can't figure out a truly mvvm way to do it. In your example here you can type letters into the field and still submit
@alejorostata3899
@alejorostata3899 Жыл бұрын
How would you trigger this, say on ICommand?
@2005bgva
@2005bgva 2 жыл бұрын
Hi SingletonSean, thanks for this video, please, please could you activate subtitles?
@clickdraw9762
@clickdraw9762 Жыл бұрын
The xaml part doesn't work form me in a .NET Framework 4.7.2 Application :(
@hishoegypt1980
@hishoegypt1980 Жыл бұрын
Hi, i've a problem>>> _propertyErrors does not have GetValueOrDefault method, what should i do?
@MagoMakes
@MagoMakes 2 ай бұрын
Same here - not sure how this guy magic'd a method in Dictionary!
@IT7kaya
@IT7kaya 2 жыл бұрын
Not able to use GetValueOrDefault() for Dictionary
@BaNaNaJoE185
@BaNaNaJoE185 2 жыл бұрын
You are probably using a different target framework... Try this: public IEnumerable GetErrors(string propertyName) { return _propertyErrors.ContainsKey(propertyName) ? _propertyErrors[propertyName] : null; }
@altair91100
@altair91100 2 жыл бұрын
where's the method OnPropertyChanged?
@r.o.9322
@r.o.9322 3 жыл бұрын
Very nice! But one thing I would have to say. Try to explain a bit more what you have to explain, not just go over some really important things like everybody already know them :) Thank u!
@SingletonSean
@SingletonSean 3 жыл бұрын
Thanks R.O! I see what you mean. I try my best to stay on topic for my videos, so I do leave out some of the basic concepts. This helps the videos stay short and concise, and also helps people find exactly what they're looking for (sometimes). I would be frustrated if I was searching "cat" in the dictionary, but the definition of "cat" was nested in the middle of a paragraph about how to sing the ABCs (I hope that's a good analogy...). I will admit it does put people who are newer to WPF at a disadvantage, which is a shame because my content should help everyone grow. To balance this, I plan to put out more fundamental videos in the future, and then link to those videos whenever I explain something that might require additional knowledge. Thanks for the feedback R.O!
@r.o.9322
@r.o.9322 3 жыл бұрын
That sounds good!
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 5 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Async Commands (and Async Relay Command) - EASY WPF (.NET CORE)
14:14
Switching Between Multiple Views in MVVM - EASY WPF (.NET CORE)
12:29
WPF Controls with MVVM: ItemsControl
33:34
IAmTimCorey
Рет қаралды 82 М.
Refactor Your App to The MVVM Community Toolkit (feat. WPF!)
30:34
SingletonSean
Рет қаралды 10 М.
Binding to a PasswordBox (MVVM) - EASY WPF (.NET CORE)
12:14
SingletonSean
Рет қаралды 20 М.
Which Software Architecture Should You Use: MVC, MVP, or MVVM?
24:27
How to Create Layout Components - EASY WPF (.NET CORE)
12:55
SingletonSean
Рет қаралды 9 М.
Я УКРАЛ ТЕЛЕФОН В МИЛАНЕ
9:18
Игорь Линк
Рет қаралды 55 М.