WPF MVVM Tutorial: Build An App with Data Binding and Commands

Sdílet
Vložit
  • čas přidán 25. 04. 2023
  • 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/TacticDevGit/Recor...
  • Věda a technologie

Komentáře • 70

  • @philsnewaddress
    @philsnewaddress Před rokem +10

    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.

    • @TacticDevs
      @TacticDevs  Před rokem +1

      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) ,

    • @philsnewaddress
      @philsnewaddress Před rokem +1

      @@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#.

  • @wawandharmawan2441
    @wawandharmawan2441 Před 5 měsíci +3

    I just learned C# and WPF about a month ago, and this video really helps me understand how MVVM works. Thank you! 👍

  • @רחל26
    @רחל26 Před rokem +1

    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.

  • @yunussurchy6359
    @yunussurchy6359 Před 10 měsíci +1

    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.

  • @angelenriquechavezponce1629
    @angelenriquechavezponce1629 Před 10 měsíci +2

    Absolutely amazing, well paced, straightforward and includes some tips and tricks here and there. You've ganiened another sub and my respect 🤝

  • @josecarloslopes5211
    @josecarloslopes5211 Před 4 dny

    great video and good teaching. Very clear explanations

  • @niangel2704
    @niangel2704 Před 10 měsíci

    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

  • @HemantChauhanMsc
    @HemantChauhanMsc Před 6 měsíci

    Thank you very much for this video, I gone through so many videos to understand MVVM but this is the best one.

  • @pierrestcergues
    @pierrestcergues Před 7 měsíci

    Thanks for all your great tutorials !

  • @xiaasafoon9427
    @xiaasafoon9427 Před rokem +1

    This video was great; it was easy to understand and clearly explained.

  • @meterdn
    @meterdn Před 11 měsíci

    i love how chill you are

  • @anirudhpuranik5222
    @anirudhpuranik5222 Před 29 dny

    Thank you, this tutorial was concise and to the point and very easy to understand!!

  • @nicolasfok5661
    @nicolasfok5661 Před 9 měsíci

    Man !, you are truly a lifesaver !

  • @RT-fi7rb
    @RT-fi7rb Před 8 měsíci

    Really Great Explanation. Thank you!!

  • @Viezieg
    @Viezieg Před 5 měsíci

    very helpful and easy to follow. thank you very much !

  • @user-qr8pl9vp1x
    @user-qr8pl9vp1x Před 9 měsíci

    Thank you very much for this tutorial.

  • @sond.v.6816
    @sond.v.6816 Před rokem

    This video was great. Thank so much

  • @lerax2010
    @lerax2010 Před měsícem

    thank you! now I finaly have an understandingthe the pattern realization

  • @shobhamahadev118
    @shobhamahadev118 Před 6 měsíci

    Peace voice, it suits to one of my friend's voice. Nice video thankyou.

  • @RoberBot
    @RoberBot Před 5 měsíci

    Really nice tutorial, good job.

  • @BeeryDorin
    @BeeryDorin Před 6 měsíci

    practical and enriching, thnx!

  • @harilalmn
    @harilalmn Před 4 měsíci

    Very helpful... Thanks!

  • @arunkumar-ru2zl
    @arunkumar-ru2zl Před rokem

    tq u very much bro for posting this video

  • @okitkin
    @okitkin Před 6 měsíci

    Thank you very much !!!))

  • @tommcmeekin1
    @tommcmeekin1 Před 8 měsíci +1

    Great video, could you do a part 2 where you add ef core and a sqlite db? Would love to see that 😀

  • @SrimalSamarasooriya
    @SrimalSamarasooriya Před rokem +3

    Cool video. Thanks for this. Small request. Can you do this with mvvm toolkit?

  • @ferenc3460
    @ferenc3460 Před rokem

    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?

  • @JitendraKumar-fo2wj
    @JitendraKumar-fo2wj Před 2 měsíci

    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

  • @janjanlara2502
    @janjanlara2502 Před rokem

    hi thank you for this video, can you make a small project tutorial using this MVVM WPF c#?

  • @TechKingdomChannel
    @TechKingdomChannel Před rokem

    i clicked Like Even Before getting 1 minute.

  • @belgabad
    @belgabad Před 3 měsíci

    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

  • @sathsarasoysa
    @sathsarasoysa Před rokem

    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?

  • @nyendwa
    @nyendwa Před rokem

    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.

    • @TacticDevs
      @TacticDevs  Před rokem

      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

  • @MattCantSpeakIt
    @MattCantSpeakIt Před 11 měsíci +2

    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?

    • @RoberBot
      @RoberBot Před 5 měsíci

      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.

  • @nyendwa
    @nyendwa Před rokem +1

    Great audio. The previous one wasn't clear.

  • @fabriziocivati8237
    @fabriziocivati8237 Před rokem +2

    Graet video but i have a question, why the filter was not included in MainVindowViewModel?

    • @nyendwa
      @nyendwa Před rokem

      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.

  • @DonaldFranciszekTusk
    @DonaldFranciszekTusk Před rokem +2

    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?

    • @TacticDevs
      @TacticDevs  Před rokem

      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

  • @niangel2704
    @niangel2704 Před 9 měsíci +1

    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😊

    • @Dan-Levi
      @Dan-Levi Před 6 měsíci

      +1 on this. Been struggling to source a good tutorial on CommunityToolkit.Mvvm for WPF, with navigation.

  • @kishiforyou
    @kishiforyou Před 3 měsíci

    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

    • @TacticDevs
      @TacticDevs  Před 3 měsíci +1

      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

  • @jreffjeff7909
    @jreffjeff7909 Před rokem +1

    My VS doesnt have the option for any of this pls help

    • @RoberBot
      @RoberBot Před 5 měsíci

      Get visual studio community, vscode isn't the best for C#

  • @niangel2704
    @niangel2704 Před 9 měsíci

    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?

    • @TacticDevs
      @TacticDevs  Před 9 měsíci +1

      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

    • @TacticDevs
      @TacticDevs  Před 9 měsíci +1

      check 28:40

    • @niangel2704
      @niangel2704 Před 9 měsíci

      @@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.

    • @TacticDevs
      @TacticDevs  Před 9 měsíci +1

      @@niangel2704 I’ll make a video on that soon over the weekend

    • @niangel2704
      @niangel2704 Před 9 měsíci

      @@TacticDevs you are a star!! I look forward to it

  • @webdevfs9361
    @webdevfs9361 Před 9 měsíci

    Your starting project structure and files are very confusing. i was trying to follow along but got lost with the styles.

  • @danilatravkov1474
    @danilatravkov1474 Před 2 měsíci

    I wonder why UserManager class is in Models folder and not it ViewModel folder.... :D

    • @TacticDevs
      @TacticDevs  Před 2 měsíci

      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

  • @uuuborovi
    @uuuborovi Před 2 měsíci +1

    ничо не понял

  • @msdevg
    @msdevg Před 6 měsíci

    Hello Thank for your video. Can you share this code. It will be very helpful.

  • @scramjet4610
    @scramjet4610 Před rokem +4

    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.

    • @RoberBot
      @RoberBot Před 5 měsíci

      This wasn't a complex example and observablecollection is just a list that can update the ui.

    • @scramjet4610
      @scramjet4610 Před 5 měsíci +1

      @@RoberBot It's complex if learning this coming from an embedded C background.

    • @RoberBot
      @RoberBot Před 5 měsíci

      @@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

  • @mohammedkaka5558
    @mohammedkaka5558 Před 8 měsíci +6

    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,

    • @RoberBot
      @RoberBot Před 5 měsíci +4

      I don't think this is a beginner video, you should watch a Wpf beginner tutorial first.

    • @manbirjudge8415
      @manbirjudge8415 Před 2 měsíci

      Its you problem. This video is definitely not meant for a beginner.