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

КОМЕНТАРІ • 81

  • @wenhanchia8448
    @wenhanchia8448 25 днів тому +3

    This deserves more recognition, thank you for the clear explanation!

    • @blayzehoodly2957
      @blayzehoodly2957 18 днів тому

      how dis
      you start this tutorial it seems all the starter code is already there when the video starts

  • @standman007
    @standman007 День тому

    This tutorial was immensely useful for me in 2024

  • @philsnewaddress
    @philsnewaddress Рік тому +12

    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  Рік тому +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 Рік тому +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 6 місяців тому +3

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

  • @yunussurchy6359
    @yunussurchy6359 Рік тому +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.

  • @anirudhpuranik5222
    @anirudhpuranik5222 2 місяці тому

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

  • @רחל26
    @רחל26 Рік тому +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.

  • @HemantChauhanMsc
    @HemantChauhanMsc 8 місяців тому

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

  • @angelenriquechavezponce1629
    @angelenriquechavezponce1629 Рік тому +2

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

  • @meterdn
    @meterdn Рік тому

    i love how chill you are

  • @bozoskopljakovic5508
    @bozoskopljakovic5508 Місяць тому

    Thanks, very simple and good example !

  • @josecarloslopes5211
    @josecarloslopes5211 Місяць тому

    great video and good teaching. Very clear explanations

  • @pierrestcergues
    @pierrestcergues 8 місяців тому

    Thanks for all your great tutorials !

  • @xiaasafoon9427
    @xiaasafoon9427 Рік тому +1

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

  • @lerax2010
    @lerax2010 2 місяці тому

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

  • @Viezieg
    @Viezieg 7 місяців тому

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

  • @nicolasfok5661
    @nicolasfok5661 10 місяців тому

    Man !, you are truly a lifesaver !

  • @niangel2704
    @niangel2704 11 місяців тому

    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

  • @shobhamahadev118
    @shobhamahadev118 7 місяців тому

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

  • @RT-fi7rb
    @RT-fi7rb 9 місяців тому

    Really Great Explanation. Thank you!!

  • @user-qr8pl9vp1x
    @user-qr8pl9vp1x 10 місяців тому

    Thank you very much for this tutorial.

  • @BeeryDorin
    @BeeryDorin 7 місяців тому

    practical and enriching, thnx!

  • @RoberBot
    @RoberBot 7 місяців тому

    Really nice tutorial, good job.

  • @harilalmn
    @harilalmn 5 місяців тому

    Very helpful... Thanks!

  • @sond.v.6816
    @sond.v.6816 Рік тому

    This video was great. Thank so much

  • @tommcmeekin1
    @tommcmeekin1 9 місяців тому +1

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

  • @arunkumar-ru2zl
    @arunkumar-ru2zl Рік тому

    tq u very much bro for posting this video

  • @okitkin
    @okitkin 8 місяців тому

    Thank you very much !!!))

  • @SrimalSamarasooriya
    @SrimalSamarasooriya Рік тому +3

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

  • @JitendraKumar-fo2wj
    @JitendraKumar-fo2wj 3 місяці тому

    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

  • @belgabad
    @belgabad 5 місяців тому

    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

  • @niangel2704
    @niangel2704 10 місяців тому +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 8 місяців тому

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

  • @MattCantSpeakIt
    @MattCantSpeakIt Рік тому +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 7 місяців тому

      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.

  • @fabriziocivati8237
    @fabriziocivati8237 Рік тому +2

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

    • @nyendwa
      @nyendwa Рік тому

      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.

  • @TechKingdomChannel
    @TechKingdomChannel Рік тому

    i clicked Like Even Before getting 1 minute.

  • @nyendwa
    @nyendwa Рік тому +1

    Great audio. The previous one wasn't clear.

  • @ferenc3460
    @ferenc3460 Рік тому

    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?

  • @kishiforyou
    @kishiforyou 5 місяців тому

    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  5 місяців тому +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

  • @nyendwa
    @nyendwa Рік тому

    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  Рік тому

      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

  • @sathsarasoysa
    @sathsarasoysa Рік тому

    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?

  • @blayzehoodly2957
    @blayzehoodly2957 18 днів тому

    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

    • @TacticDevs
      @TacticDevs  18 днів тому

      @@blayzehoodly2957 that’s just the ui code , if I start from scratch the video would be to long, since the focus is mvvm

    • @blayzehoodly2957
      @blayzehoodly2957 17 днів тому

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

  • @DonaldFranciszekTusk
    @DonaldFranciszekTusk Рік тому +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  Рік тому

      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

  • @jreffjeff7909
    @jreffjeff7909 Рік тому +1

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

    • @RoberBot
      @RoberBot 7 місяців тому

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

  • @janjanlara2502
    @janjanlara2502 Рік тому

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

  • @HOWYOUDOIN884
    @HOWYOUDOIN884 24 дні тому

    Good video but is there a video where you actually have real data stored?

  • @niangel2704
    @niangel2704 11 місяців тому

    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  11 місяців тому +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  11 місяців тому +1

      check 28:40

    • @niangel2704
      @niangel2704 10 місяців тому

      @@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  10 місяців тому +1

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

    • @niangel2704
      @niangel2704 10 місяців тому

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

  • @webdevfs9361
    @webdevfs9361 10 місяців тому

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

  • @danilatravkov1474
    @danilatravkov1474 3 місяці тому

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

    • @TacticDevs
      @TacticDevs  3 місяці тому

      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

    • @frederikkrgh7048
      @frederikkrgh7048 3 дні тому

      @@TacticDevs Is a manager class the same as what I have been taught to call a controller class?

    • @TacticDevs
      @TacticDevs  3 дні тому

      @@frederikkrgh7048 yes that for the MVC pattern however in this case we use MVVM

  • @velikanskaglava2087
    @velikanskaglava2087 7 днів тому

    Ok, just the sound is hard on the ears

  • @uuuborovi
    @uuuborovi 4 місяці тому +1

    ничо не понял

  • @scramjet4610
    @scramjet4610 Рік тому +5

    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 7 місяців тому

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

    • @scramjet4610
      @scramjet4610 7 місяців тому +1

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

    • @RoberBot
      @RoberBot 7 місяців тому

      @@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 9 місяців тому +8

    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 7 місяців тому +5

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

    • @manbirjudge8415
      @manbirjudge8415 4 місяці тому +1

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

  • @msdevg
    @msdevg 8 місяців тому

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

    • @TacticDevs
      @TacticDevs  8 місяців тому

      check the video description

    • @msdevg
      @msdevg 8 місяців тому

      Thanks