MVVM, Databinding and Dependency Injection - .NET MAUI Tutorial Step-By-Step

Поділитися
Вставка
  • Опубліковано 11 жов 2024

КОМЕНТАРІ • 127

  • @MaddCoder
    @MaddCoder Рік тому +8

    Your videos are amazing and easy to follow along. Some of the best tutorials I've seen and you're giving them to us for Free. Just wanted to let you know all your hard work and sharing your knowledge is very much appreciated!

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

      Wowow thank you so much for coming out and taking the time to say this. This is exactly the reason I do this. Thank you so much! 🥰

  • @jfversluis
    @jfversluis  2 роки тому +4

    💡Looking for the next part in this course? Click here to find it, for this one it's all about navigation in .NET MAUI: ua-cam.com/video/pBh5SXVSwXw/v-deo.html
    Want to review the full playlist? You can do that here 👉ua-cam.com/video/mgW6xviirQk/v-deo.html

  • @charlesemge3824
    @charlesemge3824 Рік тому +4

    AlsoNotifyChangeFor was changed to NotifyPropertyChangedFor -- Thanks Gerald. Just putting this at the top.

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

      Yep! Sorry about that :( check the attached repo for the latest code. Thanks for sharing!

  • @simplebright4199
    @simplebright4199 2 роки тому +2

    Appreciate your hard work gerald

    • @jfversluis
      @jfversluis  2 роки тому +1

      I appreciate that you appreciate my hard work! Thank you!

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

    Gerald! This was amazing.
    I was scared of MVVM before this video, and now I added it to my project!
    Thanks so much!

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

      This is what I make videos for Jim! This is amazing, thank you so much! 🥰 made my day!

  • @pauldb879
    @pauldb879 2 роки тому +1

    Great course, very clear and helped me a lot. Looking forward to your workshop thursday ! :)

    • @jfversluis
      @jfversluis  2 роки тому +1

      Looks like you already know it all! See you Thursday! :D

    • @pauldb879
      @pauldb879 2 роки тому

      @@jfversluis I'll look forward to the Microsoft job offer in that case ;)

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

    Your video is easier than anothers, so as like beginner for me good. Thank your your effort.

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

      That is great! Thank you so much!

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

    best maui tutorials I found so far, thanks!!

  • @darrabam
    @darrabam 2 роки тому

    44:00 LOVE IT 🤩!! Thanks

    • @jfversluis
      @jfversluis  2 роки тому

      Want to learn some more about the MVVM Toolkit?

    • @darrabam
      @darrabam 2 роки тому

      @@jfversluis if it's going to reduce my code, of course!! I've tried other mvvm packages, but nothing seemed as convenient as this one

  • @LordErnie
    @LordErnie 2 роки тому +3

    I am very impressed by the quality of the course so far. It's been done very well, great job. Do you also get into platform specific code? And will you have a part on blazor integration as well? Me and me classmates would love to see that as we do blazor right now and I'm the only one who knows Maui. It would be a great opportunity for them to start working on app development. Great content, keep it up, much love from students across Einhoven and 's-Hertogenbosch.

    • @jfversluis
      @jfversluis  2 роки тому

      Eindhoven! I will be there June 8th at .NET Zuid 😉 thanks for the kind words!
      For this course there will be no Blazor but I have a full course on also creating a .NET MAUI Blazor app planned!

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

    Man thanks for this video. I was always confused by the ViewModel duty. I work in a team of 24 people. Only 3 of us knows XAML and Im a Junior! all because i learned Silverlight while it was still new. WPF I worked at my job but I am really interested in learning MAUI

  • @fieryscorpion
    @fieryscorpion 2 роки тому +2

    Great video! Thank you!
    Will you be also covering Unit Testing in this series?

    • @jfversluis
      @jfversluis  2 роки тому +3

      Not for this series, but I'll see if I can add it to my list of future videos :)

    • @fieryscorpion
      @fieryscorpion 2 роки тому

      @@jfversluis Great. Thank you sir!

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

    Three questions about the awesome video:
    1. The collection of Monkeys is in the view model, not the model. Since the Monkeys is what we are concerned with and adding to / deleting from, shouldn't that be part of the model too?
    2. Why is the binding context set in the code-behind? Why not set it in XAML?
    3. When it came to adding to containers (dependency injection with building.Services), what exactly should be added? As I (barely, maybe not at all) understand it, any Views that depend on ViewModels; the ViewModels that they depend on; and if those ViewModels depend on Services, those as well? Is that correct?
    My doubts about dependency injection notwithstanding, I found this video to be absolutely fantastic! I really appreciated that the author waited until the end to introduce ObservableObject, I like to see (a bit) behind the curtain to see how things work, it makes me appreciate the magic even more.

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

      Thanks Michael! I try to explain the under the hood first so that there is a good understanding of what all is happening if you would do it manually. But for most of the concepts there are libraries and helpers that will make your live easier, so I add them at the end. Great to see it's appreciated!
      1. Typically your view model is tailored to whatever is shown in the view and doesn't necessarily map 1:1 to your model. Usually only whenever you're going to persist something then you will map things back to whatever it should look like for your backend and save it. If your app is not that complex and/or you don't have any need for that, use it in the model directly, there is no MVVM police that will fine you 😉
      2. You can set it in XAML, however typically it's set in the code-behind because that way you can work with dependency injection. Also, if you set the binding context in XAML and the view model needs arguments in the constructor, you can still do it in XAML, but the XAML will become quite ugly, quite fast. Ultimately it's up to you!
      3. Rule of thumb is, if you need anything injected or whatever is going to be injected needs to be registered. That typically means most of the things in your app: views, because they get view models injected, view models because they get services injected and the services because they need to be injected and potentially get other dependencies injected as well.

  • @baseljuma158
    @baseljuma158 2 роки тому

    I think adding every service and view model to dependency injection will make the application messy ... it just need to be done for services that is used in multiple places or for services that are more likely helpers . Any way even that I feel you jumped multiple steps in one lesson but I think this is the best course I followed for .NET Maui

    • @jfversluis
      @jfversluis  2 роки тому +1

      You're free to do things differently to suit your needs. If you want to not register everything, feel free to do so!

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

    In short words! The best

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

    Thank you Gerald for your great content.

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

      Thank you so much for the support! I appreciate it!

  • @sviatoslavvovnianko3357
    @sviatoslavvovnianko3357 2 роки тому

    Why do we add the ObservableProperty attribute on ObservableCollection property too?

    • @jfversluis
      @jfversluis  2 роки тому

      Technically you don't need both. With the ObservableProperty you notify the UI that a completely new instance of a collection has been assigned to the variable. With a ObservableCollection you enable the functionality to let the UI know that 1 (or more) objects inside of the collection are changing. The latter will not happen when you use a List for instance

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

    Hi Gerald, great tutorial! Thank you I really appreciate these.
    One thing I don't really understand is multiple pages that inherit from BaseViewMdoel.
    For example if a project has Page1:BaseViewModel and Page2:BaseViewModel.
    Is there two instances of BaseViewModel being created? If so, how can both pages see updated properties from BaseViewModel?
    For example, BaseViewModel has a property string Message, If Page1 changes the value, Page2 will still see an empty value or the updated value?
    I appreciate the help!

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

    you are the best teather

  • @MalithBalasooriya
    @MalithBalasooriya 2 роки тому

    Thanks for the great course Gerald. I have one issue, I do not see the CollectionView update when I click on the "Get Monkeys" button. It seems to me that the ViewModel has data, but the Page is not updated accordingly. But if you touch the CollectionView on the page, the page will be updated. Any thoughts around this?

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

    Thanks Gerald ham not seeing the text property getting binded from the model. I took the same code from your git repository ? any issues ? how can I fix that ? Can we use PRISM library here in MAUI ?

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

    Thank you so much for this! Very helpful!

  • @munawarkhurshid1201
    @munawarkhurshid1201 2 роки тому

    It would be great if you can cover the distribution of dotnet MAUI, perhaps as a single file exe (windows) or MSIX. This can very well be the final video in the series. Also would be nice to discuss implementation of menus l in AppShell using MVVM implementation to call commands in AppShell VM (Like a traditional WPF app). Overall great presentation

    • @jfversluis
      @jfversluis  2 роки тому

      Thank you! I got the distribution already covered:
      ua-cam.com/video/FNwv_W3TtSU/v-deo.html

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

    oh yeah right,i still need the BindingContext thing... x:DataType only for intelesense, then the problem come when i want to dependency injection my own service in viewmodel constructor... the BindingContext starts raising error. I Wonder if there is any way to load my own service not from constructor? OR the explanation source i read just obsolete on 2023

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

      There definitely have been some changes between the course and what is released today. I'm not 100% sure what you are asking, but as long as you register everything, services, view models and views, in the dependency injection container then it should resolve it for you.

  • @demar0228
    @demar0228 4 місяці тому

    Hi Gerald. How do you handle Dependcy injections and Tabbed pages? I'm receiving this error when I try to reference a page from my Tabbed page becuase it has Dependency Injection. Error XLS0507 Type 'HomePage' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter

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

    Great content and teaching style. Love it, subscribed.
    I have a question about the Get Monkey button which loads the data. What if I want to load the data automatically as soon as I get on a page, without the need to click any buttons? Normally in Blazor I'd put all the code for getting the data from remote source in OnInitialize() or OnInitializeAsync() method. Is there an equivalent in MAUI? Thanks!

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

      Thanks friend, welcome!
      Of course that depends a little on how and what you want to do exactly. Probably the best place to do that would be to override the OnNavigatedTo (from the top of my head) on a page.

  • @achilleaskaragiannis4947
    @achilleaskaragiannis4947 2 роки тому +1

    Why is it preferable to Clear the ObservableCollection then loop-add each element and not create a new one(like new ObservableCollection(monkeys))? aren't you firing n*collection changed instead of one property changed? Love your work and it's quality, keep it up!

    • @--Eric--
      @--Eric-- 2 роки тому

      24:20 - In that case, you have to reinitialize the data binding.

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

    Very helpful , Thank you !!

  • @RonaldRex-t8n
    @RonaldRex-t8n Рік тому

    Do you have a course covering MVVM, .Net Maui, and Delegates?

  • @alexarchangel3537
    @alexarchangel3537 2 роки тому

    Wazzup Gerald, your lessons are clear.

    • @jfversluis
      @jfversluis  2 роки тому

      That is great to hear! Thank you so much for letting me know!

  • @rahul_salokhe
    @rahul_salokhe 2 роки тому +1

    👍
    Please increase volume for next video.
    Can we call getMonkeyasync() fun. On page apering or viewmodel init ?

    • @jfversluis
      @jfversluis  2 роки тому +1

      Sure, call it whenever it makes sense to you!

  • @anandshindey
    @anandshindey 2 роки тому

    Great video Gerald. Just started catching up on MAUI. I have a question. How do i make IsBusy available to all my ViewModel classes? in Xamarin we had BaseViewModel itself where in the IsBusy was defined. What about MVVM in MAUI?

    • @jfversluis
      @jfversluis  2 роки тому +1

      You can of course create that base view model yourself or, I think the MVVM Toolkit has one built-in that you might want to use.

    • @anandshindey
      @anandshindey 2 роки тому

      @@jfversluis , Got it, thanks.

    • @anandshindey
      @anandshindey 2 роки тому

      Works. Thanks.

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

    Is there any way to pass the value of the property from the model to another variable in view model and then data bind it?

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

    did you know command has canexecute option and you can check whether thr button is enabled or not

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

    Hi Gerald, thanks a ton for all of these videos. I now understand better MVVM concept (and i'm using it in a real project). At this point, i'm stuck because of a bit more complex model involving one to many or many to many relationships. For example : A Monkey can eat one or more type of Fruit. How to create/update Monkey using Databinding in that case (with Community Toolkit) ? Can you share us a link explaining that ?

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

      Thank you! And thank you so much for supporting this channel!
      I'm not really sure if I understand what you mean... It doesn't really matter if there is a many-to-many or any other relationship. As long as you implement the INotifyPropertyChanged (or do that through the Community Toolkit MVVM) it should all just work

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

    This video really helped, thanks a lot!

  • @GuildOfCalamity
    @GuildOfCalamity 2 роки тому

    Fantastic video!

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

    Thanks!

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

    Hi, can I somehow implement Map manipulation in my code-behind. I am using a MVVM comunity toolkit

  • @jeffreyharms1469
    @jeffreyharms1469 2 роки тому

    Gerald, really good stuff here. Many times in a mvvm project, we have a separate "model" class that we use to feed the viewmodel. Do you have a suggestion for how to use the model object as part of the get/set ritual with [ObservableProperty] decoration? For example we do this "public string test { get { return testmodel.description; } {set { testmodel.description = value; }} The only thing I can see now is that when the viewmodel is initialized, I will need to populate all of the [ObservableProperty] decorated vars. Then use the [AlsoNotifyChangeFor] to set the testmodel.description. Any thoughts?

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

      The name was changed to [NotifyPropertyChangedFor]

  • @mikelockyer6653
    @mikelockyer6653 2 роки тому

    Excellent quality video and code a great help. I have though noticed that the MVVM part 5 is not working correctly when using preview 2 (Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.3.0 Preview 2.0) - the monkeys don't appear - I came across this in my code as well - seems binding is broken and can't seem to get ListView or CollectView to update - although they work on an initial fill
    So in your code I filled the Monkeys in the VM constructor and they appear OK but don't get updated correctly if you mess with update code to show only a few for example

    • @jfversluis
      @jfversluis  2 роки тому

      Yeah I got a couple of those reports. It might be bugged in .NET MAUI at the moment :( I think in the other comments there was a workaround.

    • @mikelockyer6653
      @mikelockyer6653 2 роки тому

      @@jfversluis Yes must be a bug - I found that the only thing that worked was to call ScrollTo(0, 0) on any CollectionViews after updating the ModelView

  • @tasher7882
    @tasher7882 2 роки тому

    Great refresh coarse, first time using the toolkit, and AlsoNotifyChangeFor doesn't exist. Did it get removed?

    • @jfversluis
      @jfversluis  2 роки тому

      Hehe yeah it’s kind of unfortunate. They made a very breaking change and renamed that whole thing. Check the workshop repo it should have updated code.

    • @tasher7882
      @tasher7882 2 роки тому +2

      @@jfversluis Yep I saw it in the finished it is now called NotifyPropertyChangedFor for anyone else doing the vids.

    • @pax9403
      @pax9403 2 роки тому

      @@tasher7882 Thanks for the update, also Gerald if you could pin the comment to the top of the page it would be nice to not have to look for it so far into the comments..

    • @julianesteves41
      @julianesteves41 2 роки тому

      @@tasher7882 Thanks a lot!

  • @ricardothomas3779
    @ricardothomas3779 2 роки тому +1

    Hello Gerald, great course. Keep up the good work you are doing.
    On another note, I am able to run the app on Windows but not in the emulator or on my Note 10 device.
    I get Error XABLD7000: Xamarin.Tools.Zip.ZipException: Renaming temporary file failed: Permission denied in the emulator.
    I get Error XARLP7000 Xamarin.Tools.Zip.ZipException: Renaming temporary file failed: Unknown error on my device.
    Can someone please explain why ?

    • @jfversluis
      @jfversluis  2 роки тому +1

      Thank you Ricardo! Not sure about those errors though... Maybe put that in a search engine?

    • @ricardothomas3779
      @ricardothomas3779 2 роки тому

      @@jfversluis thank you👍🏽

  • @michaelgamble2453
    @michaelgamble2453 2 роки тому

    I have been kicking around Xamarin for a while, found your course and have been following along. I did a search on the internet and found no answer, thought maybe with your experience with .NET MAUI you might have a suggestion. Up to this lesson my follow along code seems to work fine on Windows, Android, and iOS. But here I get the layout the button but no data ever appears on Android? I did some debug and sure seems to pull the data off the site, but I suspect something with the binding. I even fired up your example and the same result, yet again works on Windows, and iOS? Any ideas would be helpful.

    • @jfversluis
      @jfversluis  2 роки тому

      Ive seen that report a couple of times now so either the sample code got outdated, but since it works on other platforms the more likely scenario is; there is a bug right now for Android in .NET MAUI

    • @michaelgamble2453
      @michaelgamble2453 2 роки тому

      @@jfversluis I saw a post somewhere where it was recommended to put a "await Task.Delay(50);" to slow down the binding. I put it in the finally and seemed to work.

    • @jfversluis
      @jfversluis  2 роки тому +1

      @@michaelgamble2453 glad you figured it out! Hopefully we can resolve that soon

    • @Ghost-Boi
      @Ghost-Boi Рік тому +1

      @@michaelgamble2453 Did you put the await Task under the IsBusy=false or before I have tried both and I still have the same problem.

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

      @@Ghost-Boi I ended up getting things working. I think with a new update to VS.

  • @IvesSteve
    @IvesSteve 2 роки тому

    The latest version of CommunityToolkit.Mvvm doesn't seem to like [ObservableProperty] being used on bool? Also, What is the difference with CommunityToolkit Maui?

    • @jfversluis
      @jfversluis  2 роки тому

      Yeah they unfortunately made breaking changes between then and now. Check the workshop repository that has updated code

  • @khambleyart
    @khambleyart 4 місяці тому

    The ActivityIndicator is not showing up when I click on the "Get Monkeys" button. I added a Task.Delay(5000) so I could see it show up and it still doesn't work. It is bound to IsVisible="{Binding IsBusy}" property. When I hard-code the IsVisible to true. It shows up in the center of the screen where it should. I've tried it on both Android and iOS and it does not work.

    • @jfversluis
      @jfversluis  4 місяці тому

      Does this also show with the Final project? If yes, it might be a bug in .NET MAUI. Thanks for watching!

    • @khambleyart
      @khambleyart 4 місяці тому

      @@jfversluis Oh yeah, it works in the final project, so it must be something on my end. I'm using .NET 8 and I noticed your project is on .NET 7. Maybe that's it. I'll keep going and see what happens, I'm on part 3... Thanks!

  • @josedonizeteoliveirajunior1744
    @josedonizeteoliveirajunior1744 2 роки тому

    very good video. required duration. Thanks

  • @effectplacebo5663
    @effectplacebo5663 2 роки тому +1

    When MAUI will be realesed?

    • @jfversluis
      @jfversluis  2 роки тому +2

      Monday! 🙀

    • @effectplacebo5663
      @effectplacebo5663 2 роки тому

      @@jfversluis For real? On monday we will get actual realese, not a candidate or preview?

    • @jfversluis
      @jfversluis  2 роки тому

      @@effectplacebo5663 No release candidate or preview. It will be launched at the Microsoft Build event!

    • @effectplacebo5663
      @effectplacebo5663 2 роки тому +1

      @@jfversluis Thank you! Can not wait for this event. Also thank you for your tutorials, they are amazing

    • @tasher7882
      @tasher7882 2 роки тому

      I still can only use it in VS 2022 preview. Is that correct or am I doing something wrong.

  • @akshayjain3197
    @akshayjain3197 2 роки тому

    Is there a way we can abstract the loader also and not keeping it on every single individual page?

    • @jfversluis
      @jfversluis  2 роки тому

      There are definitely ways :) Create a base page and show it on that

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

    I don't know why but for me it feels wrong to register ViewModels in the DI Container. Is that irrational?

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

      But that's the Microsoft's documentation so far

  • @KeesAlderliesten
    @KeesAlderliesten 2 роки тому

    Is using AddRange not more efficient than adding the monkeys in a loop? Thus Monkeys.AddRange(monkeys);

    • @jfversluis
      @jfversluis  2 роки тому

      Probably, unfortunately there is no AddRange on a ObservableCollection

    • @KeesAlderliesten
      @KeesAlderliesten 2 роки тому

      @@jfversluis O, ofcourse, it's a OC and not a List, you are right!. Besides that, I have used Xamarin from v1 (a few projects, I'm not a fulltime developer) and was familiar with databinding. That helped me a lot with my current project, rewriting a 15+ year old asp.net framework application in Blazor. Same databinding concept. Now I'm catching up on MAUI and I'm delighted to see that the things I learned with Blazer (services, singletons etc) are the same in MAUI, that flattens the learning curve a lot 😉(and being 57 yo, learning isn't all that sime anymore 🤣)

  • @resler7ooo118
    @resler7ooo118 2 роки тому +1

    Super crash

  • @sviatoslavvovnianko3357
    @sviatoslavvovnianko3357 2 роки тому

    What is the diff between onClick and Command for a btn?

    • @jfversluis
      @jfversluis  2 роки тому

      Functionally not much, from a code standpoint: better separation of code

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

    At the 36:15 or so mark, the binding context was set ... But that discussion of how to resolve dependency injection, that was way to fast for me -- no idea what happened there, another one of those "look, it's magic!" moments that I'm just not a fan of.

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

      Totally understandable, unfortunately in this area there simply is a bit of magic that needs some time to wrap your head around. That's why I have multiple videos on this topic.
      Here is one for a more generic dependency injection explanation: ua-cam.com/video/tTJetZj3vg0/v-deo.html
      And here is one specific to .NET MAUI: ua-cam.com/video/wkgbvMlrMhU/v-deo.html

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

    I'm confused about is busy. Page automatically searches for that property?

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

    I am watching this in 02/2024. So there have been changes. As a result, this will not build. Error XA5301 - "Failed to generate Java type for class: AndroidX.Core.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor due to MAX_PATH: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\...\Documents\Source\Repos\MonkeyFinder\Part 2 - MVVM\MonkeyFinder\obj\Debug
    et7.0-android\android\src\mono\androidx\core\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'."
    And I have not been able to show the page on the Android Emulator (from earlier parts of the course). It gets hung up on Deploying. I waited 20 minutes for it. Can you tell me what to change to make it compatible with new emulators? I am using Visual Studio 2022 Enterprise.

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

      This had little to do with things changed over time. MAX_PATH is the key here. The generated path is too long. You might want to move it to something closer to your filesystem root. This is a limitation on Windows not .NET MAUI