WPF MVVM Tutorial: Build An App with Data Binding and Commands
Вставка
- Опубліковано 25 сер 2024
- In this video, you will learn how to use the MVVM pattern in WPF to create a app. MVVM stands for Model-View-ViewModel and it is a design pattern that helps you separate the presentation layer from the business logic and data layer of your application. You will learn how to use data binding, commands, in WPF to make your code more maintainable and testable. This video is suitable for beginners who have some basic knowledge of C# and WPF.
Source Code :
github.com/Tac...
This deserves more recognition, thank you for the clear explanation!
how dis
you start this tutorial it seems all the starter code is already there when the video starts
This tutorial was immensely useful for me in 2024
Last year I inherited a 600 dll MVVM project with poor documentation. This video has brought me so much clarity. I've been programming C# for 15 years on and off, but that has been 90% winforms and 10% MVC and some WPF, but not true MVVM. In fact this video reminds me of a tutorial I read in 1995 for C++ MFC. That "scribble" tutorial provided just the foundations of the framework and I was then able to write C++ MFC applications which I'm still doing at work nearly 30 years later. This video, I feel, covers the MVVM foundations in much the same way. Thankyou.
I'm glad to hear that the video has brought you clarity and has been helpful for understanding MVVM, It sounds like you have a strong background in C#, with experience in WinForms, MVC, speaking of C++,I was just done writing and compiling a bios flashing tool just like a day ago😅 its was exhausting( C++ is too low-Level) ,
@@TacticDevs I've never written a true kernel mode device driver but I did write a fair amount of direct windows calls years ago. I also wrote a 3D game once (1993, no libraries) which mixed assembly and C. I still prefer native over managed, but I can feel the pull of intellitype leading me towards patterns in C#.
I just learned C# and WPF about a month ago, and this video really helps me understand how MVVM works. Thank you! 👍
I decided to learn windows development using wpf, was searching and your channel popped up. i really love your videos and explanations. it would be really nice if you starting a series for newbies like me.
Thank you, this tutorial was concise and to the point and very easy to understand!!
Thank you so much for this video! after a couple of videos watching, and misunderstanding the concept, you were doing it - simply and gently! I'm happy to find your excellent video. thanks.
Thank you very much for this video, I gone through so many videos to understand MVVM but this is the best one.
Absolutely amazing, well paced, straightforward and includes some tips and tricks here and there. You've ganiened another sub and my respect 🤝
i love how chill you are
Thanks, very simple and good example !
great video and good teaching. Very clear explanations
Thanks for all your great tutorials !
This video was great; it was easy to understand and clearly explained.
thank you! now I finaly have an understandingthe the pattern realization
very helpful and easy to follow. thank you very much !
Man !, you are truly a lifesaver !
Congrats and thanx for this lovely video!! I've been coding using WinForms so far and I find it a bit difficult to adapt to the WPF. I was able to follow along and understand and justify your steps but I am afraid I dont feel comfortable to apply them to my appsm as yet. I will keep up climbing up the steep curve of learning WPF as I find it quite interesting!! Thanx again my friend!! Best regards from Greece
Peace voice, it suits to one of my friend's voice. Nice video thankyou.
Really Great Explanation. Thank you!!
Thank you very much for this tutorial.
practical and enriching, thnx!
Really nice tutorial, good job.
Very helpful... Thanks!
This video was great. Thank so much
Great video, could you do a part 2 where you add ef core and a sqlite db? Would love to see that 😀
tq u very much bro for posting this video
Thank you very much !!!))
Cool video. Thanks for this. Small request. Can you do this with mvvm toolkit?
Thanks ! Great video, just an extended question on the same, how would you implement the tab functionality on the search box? After searching the name, I want to tab to the first element and highlight the first row. TIA
Barely starting MVVM WPF and I can see some flaws in what is explained :
- The ViewModel should not reference a View at all, as I understood it opening a new windows in a MVVM-friendly manner is hard but it shouldn't be dealt with like that
- Using an event handler in the code behind is an unwanted simplification. Wether the View's code-behind should or not have anything is a discussion but the main point is that it shouldn't contain any logic, but the filtering is done entirely by the View (which also mean you can't unit-test it). The logic should be in the ViewModel, maybe through a property binded in two-way/one way to source and the filtering is called in the setter of the property
Can you do a new video with WPF, windows mvvm community toolkit and efcore to sqlite?!
This should be a piece of cake for you...
Please enlighten us😊
+1 on this. Been struggling to source a good tutorial on CommunityToolkit.Mvvm for WPF, with navigation.
Is it really okay to show a window from the viewModel? I though view models should be able to be unit tested and not depend on UI stuff like showing windows?
I think its better to show windows from the app.xaml.cpp usin g the OnStartUp method if i remember correctly
That's also the place where we create the viewmodels and everything else that might be needed like a databaseclass and then pass it to the viewmodels that might need it.
Graet video but i have a question, why the filter was not included in MainVindowViewModel?
We did not have the MainWindowViewModel class in this project, basically it is in the MainWindowViewModel except we deleted it when starting the project and added a Xaml window called "Main.Xmal" where the filter method was placed.
i clicked Like Even Before getting 1 minute.
Great audio. The previous one wasn't clear.
Hi! Thanks for your video. I have a question. So I have a window with a listbox filled with objects in it. And I move these object from one list to another in the viewmodel. But is it possible to move these object on the UI with animation using only the viewmodel anyhow?
in what scenario do we need to use icomamnd , you used command to popup a window and add a content to he list , but you did not implemented for filter any specific reason for that , kindly explain me indetail
when we stronlyg follow the mvvm pattern we must use icomamnd, the reason i didnt use it for the filter is i wanted to keep the video under 50 minutes in the future i will make a seperate video on that
Hi Jamie, I finally took time to go through this application and its platinum gold, kindly take time to respond to questions on the channel, it makes it fire. My question is, I noticed when we add a new user say, Jamie, email et al, once we close the application and open it again we no longer have Jamie as a user. Is there a way we can add Jamie in the hard-coded observable property from the user interface?
If yes, could you make a short video on that?
if not, can we then use the CRUD property using the entity framework? I hope to hear from you and you respond to my other comments.
Hi how are you doing, we cannot persistently add a user to the observable collection because that memory is only used at runtime when we shut down the application that memory is released,when the application runs again it pulls the names from the observable collection that is hard coded in the application,however we can use other means of persistent storage like a database or a file etc. We can definitely use entity framework to manipulate data in a persistent manner using a database
I want to edit and delete the data on the desktop. The Edit button must show the details of the selected student, and the user must be able to edit them. The delete button should delete the selected Data row. Can you please help me with this?
It appears you already have some code during the startup this makes it confusing how can i get the code at the level you have it at start
@@blayzehoodly2957 that’s just the ui code , if I start from scratch the video would be to long, since the focus is mvvm
@@TacticDevs yeah I noticed i was just trying to say it was going to be a lot easier if you shared the start up code so that we have the same thing when we follow through
Hi and thank You for great, peaceful explanation.
I have questions for RelayCommand class.
Why do you use Predicate? Shouldn't we use Func?
And what about CanExecuteChanged?
because the Predicate returns a boolean (true or false) , the returned boolean determines whether or not the command is enabled or disable , the predicate allows to define some custom logic that returns true of false
My VS doesnt have the option for any of this pls help
Get visual studio community, vscode isn't the best for C#
hi thank you for this video, can you make a small project tutorial using this MVVM WPF c#?
Good video but is there a video where you actually have real data stored?
Hello guys,
Does anyone know how to enable/disable the Add button of the AddUser dialog according to the contents of the textboxes? if even one of the textboxes is empty then should be disabled else enabled
Do we need another RelayCommand or event or what?
you can do that by adding some logic to canAddUser method of the adduser Command the method should return true if there is content else return false, this will automaticlly disable the adduser button when there is no content
check 28:40
@@TacticDevs this logic is what I am looking for!!
Do you mean to add a _isChanged property (in the viewmodel or in the model itself)?
And then how would the _isChanged be informed about changes in any of the User properties contents?
via NotifyPropertyChangedFor or what? Thanx in advance for your time.
@@niangel2704 I’ll make a video on that soon over the weekend
@@TacticDevs you are a star!! I look forward to it
Your starting project structure and files are very confusing. i was trying to follow along but got lost with the styles.
I wonder why UserManager class is in Models folder and not it ViewModel folder.... :D
The ViewModel folder usually contains classes that serve as databinding objects for the views (they store information to be display in the view) Since UserManager deals with managing user and not for storing information to dispaly in the view.its best to put place it in the models folder
@@TacticDevs Is a manager class the same as what I have been taught to call a controller class?
@@frederikkrgh7048 yes that for the MVC pattern however in this case we use MVVM
Ok, just the sound is hard on the ears
ничо не понял
Complicated code (ObservableCollection, complex ListView with styles, etc.) interferes with trying to learn the MVVM. The basic code should be a lot simpler so the viewer can focus on the MVVM. If viewer can easily follow this example code, then they probably already know MVVM.
This wasn't a complex example and observablecollection is just a list that can update the ui.
@@RoberBot It's complex if learning this coming from an embedded C background.
@@scramjet4610 Then yes it might be, but this isn't a Wpf beginner tutorial, this is an mvvm tutorial, you should first watch a Wpf beginner tutorial and make a small thing then come and watch this, you don't really need the mvvm pattern to make an app, you need mvvm to make a testable and maintainable app, I've build 3 wpf apps until I found out about mvvm
The issue with your tutorial is it is totally not friendly for beginners, for example, a new user does not know how to design the windows and setup the project files, i think you should address this in your tutorials,
I don't think this is a beginner video, you should watch a Wpf beginner tutorial first.
Its you problem. This video is definitely not meant for a beginner.
Hello Thank for your video. Can you share this code. It will be very helpful.
check the video description
Thanks