Intro to Model-View-ViewModel (MVVM) Pattern for WPF in C#

  Рет қаралды 349,901

David Anderson

David Anderson

Күн бұрын

Introduction tutorial of the Model-View-ViewModel architectural design pattern for WPF in C# that covers the basic fundamentals of the pattern, its purpose, and how to use it.
Source Code:
www.danderson.io/posts/mvvm-se...
#wpf #mvvm #dcomengineering

Пікірлер: 287
@MateusGomes-hp3jr
@MateusGomes-hp3jr 2 жыл бұрын
9 years later and it is still one of the best MVVM tutorials. Great explanation.
@aleksey1799
@aleksey1799 4 жыл бұрын
The most approachable wpf mvvm basics short lesson I've seen!
@rickd32
@rickd32 10 жыл бұрын
Thanks David! This is by far the best C#/WPF tutorial I have come across. Very well explained and easy to follow along. I'm looking forward checking out the rest of your posts.
@DX7Dev
@DX7Dev 10 жыл бұрын
Thanks, glad to hear! Uploaded a new one recently!
@chandantiwari2441
@chandantiwari2441 10 жыл бұрын
New to MVVM, looking for right source to start with, Go for this tutorial, you will not be disappointed believe me !. This is the simplest possible explanation I ever had seen on youtube.
@Orww
@Orww 9 жыл бұрын
I'm a complete newbie to WPF/MVVM and this has helped me greatly, as opposed to some other resources out there. Thank you!
@scotolivera8207
@scotolivera8207 2 жыл бұрын
almost 9 years passed, and still helpful, thanks
@jamesvalery9367
@jamesvalery9367 3 жыл бұрын
Thank you so much for this!! Short and simple.
@neeleshbodgal7479
@neeleshbodgal7479 6 жыл бұрын
I am glad that such a tut exists which explains the MVVM with easy and focus on essentials. I have visited reading about patterns but relatively this is more easy to understand the basic essence of MVVM and related features of wpf too. Thanks for making it. Looking forward to more tuts that would give more insight on problems faced in the pattern and suggestions to overcome in design if any.
@michor10
@michor10 6 жыл бұрын
I know this is an old video but I just wanted to say that it is great and really helpful. Excellent production. Thanks!
@NoOne-wf6hm
@NoOne-wf6hm 2 жыл бұрын
"Mr. Anderson..." Good Job! (Thumbs Up)
@danielfridman8317
@danielfridman8317 2 жыл бұрын
Finally, simple and clear explanation!
@PaulSebastianM
@PaulSebastianM 11 жыл бұрын
Finally, how long I have searched! Thank you!
@rajguru01583
@rajguru01583 9 жыл бұрын
Simply Awesome! Thanks for Sharing! Short and Effectively!
@rezaahmadi6128
@rezaahmadi6128 10 жыл бұрын
Really nice video! Thanks David! Keep doing awesome work.
@frederickfoster3218
@frederickfoster3218 11 жыл бұрын
Oh that is great point regarding Models. When I first started looking at MVVM. I got impression that VM was getting too much responsibility... but I like this a lot "(eg. Customer > CustomerModel > ViewModel > View)." Thanks for taking your time - this was very helpful, I almost went the wrong the way with my design :)
@daveconnors62
@daveconnors62 10 жыл бұрын
brilliant tutorial. finally understand what MVVM is aiming to achieve, and how it achieves it
@levkhromov4852
@levkhromov4852 10 жыл бұрын
Great. Best WPF tutorial I've seen. Hope you will continue gladdening our hearts and minds :)
@DX7Dev
@DX7Dev 10 жыл бұрын
Thanks! I really appreciate it!
@lilyflowerangel
@lilyflowerangel 6 жыл бұрын
Amazing tutorial. Thank you for this!
@swingymcswing
@swingymcswing 9 жыл бұрын
I'm slowly getting into WPF/MVVM for work(C# 7yrs) and I can say that your videos have helped me get a grasp of what is going on in this pattern. I was truly clueless before, and still, a long way to go.
@thomashcullen3253
@thomashcullen3253 9 жыл бұрын
swingymcswing Hi swingymcswing.. You deserve a house, for free.
@DX7Dev
@DX7Dev 11 жыл бұрын
I'm glad you were able to get it working, and thank you for the feedback. Glad you like my video. :)
@davidnstevenson
@davidnstevenson 9 жыл бұрын
Quite the best, most practical introduction to MVVM I've seen. Excellent.
@thomashcullen3253
@thomashcullen3253 9 жыл бұрын
David Stevenson Hi David.. You deserve a house, for free.
@invaden5605
@invaden5605 6 жыл бұрын
Great presentations, Congrats and thank you. These 3 videos were very helpfull.
@pranavsv
@pranavsv 11 жыл бұрын
I must say I've been every where on Internet looking for something that could get me started "How to actually use MVVM"? All those 300+ pages books must be good for later reading but trust me...if you want to start MVVM, this video is the place!! David you rock!! Thanks.
@04Bovo
@04Bovo 8 жыл бұрын
Thank YOU!! this helped me sooooo much! wonderful video!
@Twisterzemun
@Twisterzemun 9 жыл бұрын
Awesome tutorial, thanks alot for this! :D
@ChristopherLoyd1
@ChristopherLoyd1 11 жыл бұрын
Great Video. I'm brand new to .NET programming, C# and the MVVM patterns and principles - this video helped bridge some gaps for me on exactly how MVVM worked with WPF. Thank you so much!
@kennethkiiza8026
@kennethkiiza8026 11 жыл бұрын
Way to go man. Just starting out - in anticipation of a major WPF project coming my way soon. Looking forward to the next offering.
@asbmud
@asbmud 9 жыл бұрын
Great video tutorial. Congrats!
@cmtyler
@cmtyler 12 жыл бұрын
Great explanation of MVVM!! Easy to understand. Thanks!
@borisprymost
@borisprymost 11 жыл бұрын
Thanks a lot! Very nice tutorial. I was always kinda scared to use bindings. Mostly because i didn't understand them. But now i see how awesome they are.
@eitzhadas
@eitzhadas 7 жыл бұрын
Thanks for the great video! Btw, I see you constantly copy/paste text in order to reorder lines, you should know this - you can use the Alt-Arrows keys to do the same much quicker, efficient, and cleaner.
@DX7Dev
@DX7Dev 7 жыл бұрын
Thanks for the tip!
@mariasarabia1958
@mariasarabia1958 7 жыл бұрын
Paw patrol
@jespersails
@jespersails 10 жыл бұрын
Very nicely done david ! Your video cleared all the doubts i had in my mind !
@kernildojunior
@kernildojunior 8 жыл бұрын
Excellent video ! Well explained ... thanks a lot for sharing knowledge and congratulations !
@robertthomas8813
@robertthomas8813 4 жыл бұрын
Good instruction and clear voice, nice demo !!
@damianzelazny5785
@damianzelazny5785 11 жыл бұрын
Excellent explanation ! Thanks for great tutorial.
@Faygris
@Faygris 4 жыл бұрын
I can't believe you added the whole OnPropertyChanged logic via a custom code-snippet without explaining it at all
@DX7Dev
@DX7Dev 4 жыл бұрын
It's a bit assumed that it's prerequisite knowledge these days! Change notification has been around for awhile now!
@nemanjaq
@nemanjaq 11 жыл бұрын
Thank you very much. Very interesting and clear step by step guide. Cheers!
@DX7Dev
@DX7Dev 11 жыл бұрын
Thanks for the feedback. I usually put links to the code in my video descriptions, but if you would like all three packaged into a single project, may I recommend holding out for the next MVVM video. The next MVVM video we will go through making an entire MVVM application. Something simple, but from start to finish, including unit tests.
@gimmyig
@gimmyig 10 жыл бұрын
Nice Tutorial! Thanks
@ahmadfatahian5368
@ahmadfatahian5368 11 жыл бұрын
Thanks David. Great Turorial.
@tdkboxster
@tdkboxster 11 жыл бұрын
Fantastic video, great effort. Truly appreciate it.
@rosspatel3526
@rosspatel3526 10 жыл бұрын
This might be the best c# tutorial I have seen on youtube. Very well explained, not just code to re-type. Thanks.
@RobertButterworth
@RobertButterworth 10 жыл бұрын
It is a pretty good tutorial! it's a shame that you end up with so much more code when using MVVM than straight winforms :S
@SteveTheodore480BC
@SteveTheodore480BC 10 жыл бұрын
Up to a point - but afterwards I find it's less work, since using bindings and observable collections usually removes a ton of irritating 'if this is selected then highlight that' boilerplate. For things like rich lists its a big win
@RobertButterworth
@RobertButterworth 10 жыл бұрын
Yep, just got to make sure that your app hits that point and continues for a bit. I'm in the middle of said point. :S
@SteveTheodore480BC
@SteveTheodore480BC 10 жыл бұрын
Of course, there's the whole "I just got comfortable with WPF and now its obsolete" thing to consider too...
@RobertButterworth
@RobertButterworth 10 жыл бұрын
Lol!!!
@Itelfig
@Itelfig 11 жыл бұрын
Thanks for clearing those things out for me :)
@user-fk7mt5st4n
@user-fk7mt5st4n 10 жыл бұрын
This is a really good tutorial. You just write code and dont explain every single letter as if the listener was an idiot. Thanks
@MrProgrammer101
@MrProgrammer101 10 жыл бұрын
Awesome video super clear and simple. It was a big help thank you!
@DX7Dev
@DX7Dev 10 жыл бұрын
You're welcome! Thanks for the feedback!
@DX7Dev
@DX7Dev 11 жыл бұрын
Thanks for the feedback. I have made a note of this from multiple comments regarding hotkey usage and will make an effort to point these things out.
@sudani1969
@sudani1969 10 жыл бұрын
Wow i was looking fr simple and clear tutorial...and here it is looking for more tutorials
@DavidAnderson-cj3ux
@DavidAnderson-cj3ux 10 жыл бұрын
Thank for the feedback. I just uploaded a new video this morning, and there are more on the way :)
@TheAjr10
@TheAjr10 8 жыл бұрын
Thank you! Great content.
@undtakr
@undtakr 11 жыл бұрын
David I wrote earlier about the app.xaml causing an exception. I figured out what it was and it works now. This is a great video since I'm new to the whole MVVM and wpf stuff.
@ethanwint3930
@ethanwint3930 2 жыл бұрын
I'm new to WPF this was extremely helpful
@DX7Dev
@DX7Dev 11 жыл бұрын
Thank you for the feedback. I do know that you can set the data context directly from Xaml, though I don't remember why I chose not to demonstrate that in this particular video. At any rate, in Session 03 I use that technique which prevents any code-behind at all. Glad you liked the videos, more to come for sure.
@fraukline4503
@fraukline4503 8 жыл бұрын
Bravo!! Very nice. Thanks!
@RosenmeierCPH
@RosenmeierCPH 10 жыл бұрын
Very nice tutorial. It really help me understand data bindings.
@DX7Dev
@DX7Dev 12 жыл бұрын
Thanks for the feedback cmtyler. There will be an MVVM Session 02 coming soon as well.
@DX7Dev
@DX7Dev 11 жыл бұрын
Glad everything has been sorted out for you. Hope you are having fun with WPF/MVVM!
@DX7Dev
@DX7Dev 11 жыл бұрын
Glad it helped! Happy coding!
@jogribaer
@jogribaer 10 жыл бұрын
Thank you very much for this awesome tutorial :)
@DX7Dev
@DX7Dev 10 жыл бұрын
You're welcome! Glad you enjoyed it!
@piggyefromhell
@piggyefromhell 11 жыл бұрын
Very nice tutorial!
@benjamwondafrash4857
@benjamwondafrash4857 11 жыл бұрын
Thanks undtkr! I tried "Views.MainWindow". Dot instead of "/". I am a total beginner with WPF, so your quick reply was priceless.
@ArturMichajluk
@ArturMichajluk 10 жыл бұрын
Nice tutorial. I'm looking for tutorial for my friend and I give him your's. Few things for you: 1. You can create DataContext in xaml and keep code behind untouched. 2. And for defining props you can use 'propfull' snippet. Or (as i've done) create similar snippet for OnPropertyChanged props. (I called it propnotify). Once again, nice tutorial.
@bioanu
@bioanu Жыл бұрын
Excellent, excellent, excellent!!!!
@DX7Dev
@DX7Dev 11 жыл бұрын
Thanks! There are two other videos in this series I did, which you can see on my channel. Definitely more to come.
@DX7Dev
@DX7Dev 11 жыл бұрын
Both are valid approaches; it just depends on your needs and how much code you want to duplicate. This is called model wrapping and is a great approach for wrapping models that do not implement INotifyPropertyChanged. I tend to wrap models when I don't want the bindings to be coupled to the model. This makes it easier to replace the model at a later date with something else if need be.
@VongolaFamilie
@VongolaFamilie 5 жыл бұрын
Good Video, helped me understand the System MVVM better.
@thehope1999
@thehope1999 10 жыл бұрын
Excellent, thank you.
@bezbos
@bezbos 6 жыл бұрын
This is a very good explanation and demonstration of *MVVM*. Some things just clicked for me. I do however need to see how "_ICommand_" works.
@amalshalika6803
@amalshalika6803 10 жыл бұрын
good one.. simple and helpful...
@amrgaber4662
@amrgaber4662 6 жыл бұрын
Great Work .. thanks شكرا
@Zooral45
@Zooral45 3 жыл бұрын
This is great and I'm looking forward for the rest. How is this not a top video by now? :/
@DX7Dev
@DX7Dev 3 жыл бұрын
It was a top video for quite a while but its pretty old now. Thanks for the feedback
@shashikantpatil2913
@shashikantpatil2913 11 жыл бұрын
Great David.
@upsnipster
@upsnipster 10 жыл бұрын
This video is great. I feel enlightened after watching.
@DX7Dev
@DX7Dev 10 жыл бұрын
That is the intent, so I'm glad I accomplished the goal. Thanks for the feedback!
@supertong-things
@supertong-things 10 жыл бұрын
Thanks, it helps me a lots.
@hansjd
@hansjd 9 жыл бұрын
AWSOME!
@duannguyen1550
@duannguyen1550 10 жыл бұрын
Great video.
@DX7Dev
@DX7Dev 11 жыл бұрын
Yeah, I use a lot of hotkeys. CTRL+. is most common, but now I've started using ReSharper and I use ALT+ENTER a lot for the refactoring options. Definitely a great tool that I highly recommend.
@mthomsonkiwi
@mthomsonkiwi 11 жыл бұрын
Thanks David! I learned a ton. Threw me for a while when things were just appearing because your using shortcut keys etc. If you could call out what your pressing, that would be helpful for those of us that aren't power users yet! :D
@anjnakhanna630
@anjnakhanna630 8 жыл бұрын
Very good explanation of MVVM.
@Suriyaakter
@Suriyaakter 11 жыл бұрын
Hey David, Nice, clean and simple way to talk about MVVM. Also thanks for uploading source code (at your site). It would be great help if we able to read the code while you explain in video, please increase the fonts (in coming sessions). Thanks once again.
@cbttjm
@cbttjm 10 жыл бұрын
Thanks very much!
@juanpedro8775
@juanpedro8775 10 жыл бұрын
Great Tutorial
@DavidAnderson-cj3ux
@DavidAnderson-cj3ux 10 жыл бұрын
Thanks!
10 жыл бұрын
Thank you very much!
@DX7Dev
@DX7Dev 11 жыл бұрын
You are exactly right! But, sometimes to get people started it is best to take an easier approach where they can focus on smaller parts at a time. My next video will approach the major differences between a model and view model, and where models actually come from. Thanks for the feedback.
@saml9615
@saml9615 10 жыл бұрын
Wow. Great work man.
@DavidAnderson-cj3ux
@DavidAnderson-cj3ux 10 жыл бұрын
Thanks man!
@DX7Dev
@DX7Dev 11 жыл бұрын
Thanks for the feedback. Updated the description. Also check out the other two MVVM videos on the series on my channel.
@DX7Dev
@DX7Dev 11 жыл бұрын
Thanks!
@Alexander-jr1yk
@Alexander-jr1yk 3 жыл бұрын
Now are datacontext, binding, MVVM, etc for me also crisp and clear. Thanks.
@rajeshkhakhar6279
@rajeshkhakhar6279 10 жыл бұрын
excellent video.... thanks for sharing the same
@bkboggy
@bkboggy 10 жыл бұрын
How come you moved your using statement into namespace context in the Customer class?
@bsdisaster
@bsdisaster 6 жыл бұрын
Love the tutorial. It really helped. I run into one challenge thought. I am building an app where the user controls have to be dynamically created based on values of users preferences. How do I create click events for controls I don't know will exist until runtime? This is simple to do in the code behind, but I can't even fathom how in a view model.
@DX7Dev
@DX7Dev 11 жыл бұрын
I'm more of an explicit developer for readability, which is why you will find me explicitly declaring things like internal, even though it is the default. As for the using statements, there is a small difference in putting them inside or outside a namespace, but I cannot post any links in comments so you will have to search StackOverflow for the popular answer, or just read the C# specification. Thanks for the questions and feedback.
@DX7Dev
@DX7Dev 11 жыл бұрын
CTRL+. is a built-in shortcut that brings up a menu for certain actions, such as adding missing using statements, creating new types, etc. I also have tons of extensions in Visual Studio so if you watch some of my more recent videos you may see more "shortcuts". :)
@frederickfoster3218
@frederickfoster3218 11 жыл бұрын
Cant wait to see more of MVVM videos - I think I might use what you covered in #3 soon :). 1 question/suggestion. When you bind Name to the textBox you use "Binding Customer.Name" - I do not like that, I would much rather have "Binding CustomerName" where CustomerName is string property in ViewModel which gets and sets Customer.Name. This way if something changes about Customer, it is less likely I would have to do anything with View I would just change VM. I would appreciate your feedback
@eviscero
@eviscero 8 жыл бұрын
This video was excellent. Please tell me you have one for threading.
@kicknotes
@kicknotes 9 жыл бұрын
Good video. I think WPF+MVVM is great, but I'm always a bit turned off by the amount of standard scaffolding required for command handling without using something like IRoutedCommand or a framework like Caliburn Micro. Nonetheless, good video... will watch the others.
@DX7Dev
@DX7Dev 9 жыл бұрын
kicknotes Will be doing a Q&A video tomorrow.
@thomashcullen3253
@thomashcullen3253 9 жыл бұрын
kicknotes Hi kicknotes.. You deserve a house, for free.
@DX7Dev
@DX7Dev 11 жыл бұрын
You implement INotifyPropertyChanged so that if the value of a property on the model changes from your model or view model, the view is notified of that change and can update the display. Otherwise without it, WPF doesn't know when a value changes and will display an old value. You do not need to implement the interface to support changing the value from the view however.
@russw6566
@russw6566 9 жыл бұрын
Is it a good idea to expose the model (like you are doing) directly on the view model without wrapping it? You're creating an indirect reference from model to view through databinding. Do you think it would be better to use proxies for the properties on your customer model or not?
@erankitmalviyans
@erankitmalviyans 11 жыл бұрын
Thanks David
@b0570nk4
@b0570nk4 9 жыл бұрын
hello, first i'd like to thank you for this tutorial, it was really helpful. now after little bit of practice i am trying to properly apply this knowledge however i am having hard time with 2 things related to mvvm. q1 - How should i bind observeableCollection in the view's itemssource itemTemplate? let's say i have a ListView which's item's source is ObserveableCollection and with 3 gridviewColumns each binding to a property of MyModel (FirstName, Email, etc.) should i wrap the Model into ModelVM and expose model's properties in it? because currently my model has NotifyPropertyChanged and i believe it should not due to model-view separation goal we want to eachieve, correct? q2 - who is responsible for defining business logic? is it MVVM-ok if my ViewModel's class has a method lets say "ComputeChecksum"? Or should it rather be in some other class lets say "CoreFuncs" in order to keep the ViewModel businessLogic-clean? and yes - i have tried to use google, but the conversations i've found were not satisfying me
@DX7Dev
@DX7Dev 11 жыл бұрын
Normally you would create a view that contains the menu with a view model behind it. It is a bit of work, but it pays off in the end because its quite flexible, easy to maintain, and easy to change.
@billaps
@billaps 9 жыл бұрын
Thank you for the video. I have one question: Since both the update button and the text area have bindings with the Customer.Name, what is the difference between them? I mean, typing a name already changes the Customer.Name property, even if the update button does not get clicked.
Multiple WPF Views and View-Models using MVVM in C#
19:00
David Anderson
Рет қаралды 140 М.
Useful gadget for styling hair 🤩💖 #gadgets #hairstyle
00:20
FLIP FLOP Hacks
Рет қаралды 11 МЛН
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 11 МЛН
How much does the Windows Community MVVM Toolkit REALLY help us?
7:02
Is LEARNING WPF still WORTH it in 2023?
10:59
tutorialsEU
Рет қаралды 45 М.
Шаблон MVVM по-простому. ViewModel. AndroidViewModel. AndroidViewModelFactory
14:37
Мобильный разработчик | Юрий Петров
Рет қаралды 24 М.
What is MVVM (Model-View-ViewModel) Pattern?
10:08
Programming with Mosh
Рет қаралды 327 М.
STOP Learning These Programming Languages (for Beginners)
5:25
Andy Sterkowitz
Рет қаралды 673 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 257 М.
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 1,1 МЛН
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 4,4 МЛН
Это iPhone 16
0:52
Wylsacom
Рет қаралды 1,2 МЛН
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 13 МЛН
ноутбуки от 7.900 в тг laptopshoptop
0:14
Ноутбуковая лавка
Рет қаралды 3,6 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 603 М.