C# WPF UI Tutorials: 03 – View Model MVVM Basics | Video



Part of a series of tutorials on creating WPF applications in C#

Converts the previous TreeView demo application from code-behind to much better View Model MVVM application

Source code here: https://github.com/angelsix/youtube
Proudly WWW.PONIREVO.COM

READ ALSO:  Self Defeating Species

Source

48 Comments

  1. I studied what you have done that I needed to see last video and this video twice to do it from my mind and relate with pen and paper. I Can't thank you enough I will proceed with the videos.

  2. Great Tutorial, greetings from Germany. Just one question. I don't get why we need the RelayCommand or the ExpandCommand in the DirecotryItemViewModel. I can comment this in the constructor and it still works since we have bound isExpanded. So why do we need that? However, you're doing great work! Keep it up

  3. On the GetLogicalDrives() I have an issue :"Inconsistent accessibility: return type 'List<DirectoryItem>' is less accessible than method 'DirectoryStructure.GetLogicalDrives()'"

    Please help

  4. Question here. I may have missed something but I understand how the DirectoryStructureViewModel was bound to the ui. However I do not understand how the DirectoryItemViewModel was? From what I can tell it is looking to both viewmodels without any binding to the DirectoryItemViewModel. Also, if that is the case what would happen if you were to have two variables of the same name. How would it know which to use?

  5. Do you even need the Fody.PropertyChanged considering ObservableCollection fires up it's event every time it is modified? In my code I just made sure I either .Clear() or .Add() to collection on .Expand() and .Collapse() and it worked fined without me having to call PropertyChanged event once.

  6. hello, is there a way to populate items like buttons starting from the center of user control and it continues in a clockwise manner?
    Also is there a way to construct cells(with rows and columns) in user control and then refer a specific cell to bind something on it

  7. Visual Studio says [ImplementPropertyChanged] is now deprecated, is that still the thing to use for that fody extension? (Awesome videos btw).

  8. Hi Luke, I was following your video, great as usual. However, i can't figure out how does the command is hooked up. It is not referenced in the xaml, nor in the code behind. Is there any convention, default behaviour which is in play here ? Thank you

  9. This guy is actually very good at explaining the things that you are thinking in the back of your mind when you watch 99% of other tutorials. Explaining why things are the way they are. Good work, keep it up.

  10. You can still get the Fody package(s) to work. Just install the same versions used in the video, namely:
    Fody v 1.29.2
    PropertyChanged.Fody v 1.52.1
    It makes it easier to follow along with the video if this is all new to you.

  11. From the viewmodels in the video, If I wanted to create a new view with details (last modified, extension etc) of a file selected in the treeview via a button. Would I create a new viewmodel? I'm just wondering how I would pass the object over, so I can then get the file details and display them. Thanks

  12. Shame after the refactoring you didn't show open/closed folder icon based on IsExpanded. Would have liked to have seen how you implemented that tweak

  13. instead of assigning the DataContext in code behind, I like to do it in xaml, as below: This gives you intellisense for your bindings. Doesn't work for 100% of them, but it's nice.

    <Window.DataContext>
    <local:DirectoryStructureViewModel/>
    </Window.DataContext>

  14. Hi mate, used this video a lot for reference when learning MVVM, thanks a lot. I'm currently designing a system from scratch, and to hook up my model and view model I've simply passed each model to its relevant view model via the view model constructor. Is there any reason why this might be bad design principle? Any help would be appreciated, cheers!

  15. This is easy in theory only. Implementation is a massive pain in the dick. I've watched the video for the first time two days ago. Today, I've been at it for about 7 hours now. I have one property and one command. Took me the entire day to get this far and now I'm stuck again because I don't know how to figure out which button triggered the command. I'm not saying I'm briliant and understand thing instantly, but this is by far the most painful thing I've encounter while learning code the past 3 months.

  16. is something like putting nameof(x) a common thing for most languages? I can't believe I've never heard of this before now.

  17. igot the drives but im not getting the folders??
    its binded properly im getting all folders in the property but its not in coming in the view

  18. Hello Luke,
    Great video again, I was wondering about the nature of it being portable, you said the code can be reused and ported to different platforms (37:39). Could you tell in a little more detail as to how the C# code can be used as the backend logic, in conjunction with other UI frameworks to build a DesktopApp on Linux/MacOS. With .NET Core we have some deployment choices but its not of much use if you want to build a cross platform desktop app.
    Thanks in advance ..

  19. Is there any way of searching through the tree view using a search box? I attempted to try it using the method used within your Searching Chat Messages List Filter video but it didn't seem to be much help

  20. I really like your videos, and they explain well. But I think the example pick up to show the MVVM Basics is not that straight, should have focus on something that would show the logic between the properties binding, and not focus so much on the treeview code.

  21. @5:08 — No, "enum" is short for "Enumeration" (not "Enumerator" or "Enumerable" — those are classes that implement IEnumerator / IEnumerable respectively, and are used for traversing collections).

  22. PropertyChanged.Fody 2.6.0 now uses AddINotifyPropertyChangedInterface which adds the interface and the event handler automatically.

  23. To anyone watching this in the future: i tend to pause the videos, trying to understand what just happened, doing it myself.
    I recommend to you: do not do that with this video. Watch it to the end and then redo it. The whole concept needs a lot of parts to work, and if you stop half way through you are missing pieces to redo the content on your own.
    That said: these are by far the best tutorial videos on wpf on the internet. Insanely well done and i loved that it just assumes you know C# and doesn't waste time explaining trivial stuff.

  24. Have you got any tutorials around using charts. I’ve been looking for one can’t find anything that’s good.

  25. Hey There, Thanks so much for this. Btw, I have recently downloaded .NET Core 3 onto both my Windows and Mac. I'm building an app on Windows first, and will then port it to Mac. I believe I am realising the brilliance of your approach! Correct me if I'm wrong but most of the non-WPF code, if written in .NET Core 3, can be re-used for a Mac implementation yes?? Also, is this where the RelayCommand really comes into play i.e. on another platform such as a Mac?

  26. Hi, thanks for your tutorial. Could you please help me in implementing the tree view without using the Fody PropertyChanged Nuget package? I tried it without using the package. However, I am getting only the drive name and whenever I am clicking on the drives, the children are not appearing along with them. Please help me regarding this, I will be very much grateful to you.

  27. Hey @AngelSix, love your tutorials. I had an issue with adding the Fody Weavers package, version at the time I installed (PropertyChanged.Fody v2.5.13; Fody v3.2.17), it didn't actually add in the FodyWeavers.xml file to the project which confused me for a while. I don't know if something changed along the way from the version you used to the one I installed. I did end up manually adding it in, but not sure if there is something I missed or something in the package behavior changed. The attribute name has definitely changed.

  28. Hello. I've followed through this tutorial and it works well; thanks. I've been trying to amend HeaderToImageConverter.cs to case the File type so that I could access the full path of the file in order to determine the type of file by the extension, and so set the image to the appropriate type of file. I have failed miserably. Could you point me in the right direction, please? or this is too cheeky a request?

  29. This series is outstanding. The best part here is the mentor who seems to be a professional developer with a lot of experience. We find few videos by professional devs on web. Thanks Luke 🙂

Comments are closed.