Even More MVVM Source Generator Awesomeness for .NET Developers

Sdílet
Vložit
  • čas přidán 3. 08. 2024
  • Regardless if you are developing a .NET MAUI, WPF, WinUI, Uno, or Avalonia app, if you are using MVVM then you need to be using the .NET Community Toolkit for MVVM. It is full of amazing features for developers including fantastic source generators that take all of the hard work for you. I have learned a bunch since my first video including new partial methods, new interfaces, and new features that were in the original release. The fun doesn't stop there as there is a brand new release that adds a few new features for developers and tons of performance improvements. I break it all down.
    Links:
    Code - github.com/jamesmontemagno/mv...
    .NET Community Toolkit - github.com/communitytoolkit/d...
    Blog Announcement of 8.1 - devblogs.microsoft.com/dotnet...
    .NET Conf Video - • MVVM is easier than ev...
    Chapters:
    00:00 - Intro
    00:32 - Source Generators Overview
    03:55 - Partial Methods On Changed/Changing
    05:15 - Multiple Attributes on One Line
    05:45 - RelayCommand: IsRunning, Cancel, and More
    08:45 - INotifyPropertyChanged or ObservableObject
    09:23 - New Features in 8.1 - Performance and Json Serialization Properties
    11:40 - Wrap-up
    Join this channel to get access to perks:
    / @jamesmontemagno
    👕 Buy some swag! - jamesmontemagno.myspreadshop....
    ☕️ Buy me a coffee - www.buymeacoffee.com/jamesmon...
    Follow:
    👨‍💻 GitHub: github.com/jamesmontemagno
    🦜 Twitter: / jamesmontemagno
    📄 Website: www.montemagno.com
    📰 Newsletter: newsletter.montemagno.com/
    Disclaimer: This channel, videos, and streams are created in my spare time and are a product of me... James Montemagno! They are NOT officially affiliated or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.
    What is on my hat? It is the CLE clothing logo because I am from Cleveland! Checkout their awesome CLE merch: cleclothingco.myshopify.com/
    What is that art on my wall? It is an original piece from the French street artist Gregos of La Butte Montmartre: / bcez1onhiqx
    My Setup:
    📷 Canon M50 Mark II - amzn.to/3P8R7lp
    💡 Nanoleaf Elements Lights - amzn.to/3umwJVW
    🎙 Blue Spark Microphone - amzn.to/3qgtYkq
    🎙 Blue Pop Filter - amzn.to/3jEWM3r
    🤳 Rode Microphone Arm - amzn.to/2Z68AlE
    🎧 Sony MDR7306 Headphones - amzn.to/372jxta
    📲 Stream Deck - amzn.to/373Uk1n
    📹 Elgato Cam Link - amzn.to/3a9eGbh
    📷 GoPro Hero - amzn.to/374lm90
    🖱 MX Master 2S Mouse - amzn.to/3d7J2gj
    ⌨️ Tecware Phantom Keyboard - amzn.to/3aUP4y9
    #dotnet #dotnetmaui #wpf #sourcegenerators #avalonia
  • Věda a technologie

Komentáře • 54

  • @deaasaleh3613
    @deaasaleh3613 Před rokem +2

    Thank you James
    We are waiting for more videos about MAUI from you

  • @bkaankose
    @bkaankose Před rokem +11

    Source generators are amazing and it's exactly what was needed for many years. One thing I dislike in VS though, don't know if it's there but when we Go To Definition in XAML by F12, it takes us to the generated source code which we are not literally interested in most of the time. Not sure whether there's an option in VS to change this behavior like "Don't go to the definitions in generated source code by source generators" etc, but will create feedback if it's not there.
    Thanks for the video!

  • @berlinerffm
    @berlinerffm Před rokem

    Thanks for this video. Having the option to add Json-Properties is really the one thing I was missing in Release 8.

  • @MaximilienNoal
    @MaximilienNoal Před rokem +1

    I've been using it wirh AvaloniaUI since your first video. I absolutely love it ! My fingers are so thankful !

  • @glenmackay6539
    @glenmackay6539 Před rokem +6

    Great Video James.
    The MVVM community toolkit makes a huge difference to the effort required to making the MVVM concept work. On top of that XAML the VisualStateManager tags allow a very good way to make the interface look responsive. Almost at the point where I can ditch the code behind now....

  • @goldenwolf2621
    @goldenwolf2621 Před rokem +1

    That is very amazing 👏 like i really love the community toolkit right now and it will be a must in any of my projects

  • @CarminaIguana
    @CarminaIguana Před rokem +2

    +1 for "plethora"

  • @yvanbrunel9734
    @yvanbrunel9734 Před rokem

    Thanks a whole lot for everything, I'm literally in a bus traveling, but I watching your video and thinking of how much it's going to improve my code 🤣
    Thanks a lot!

  • @sheilainglin863
    @sheilainglin863 Před rokem

    Great video James!! 🌞🌞🌞🌞🌞🌞

  • @maxm1079
    @maxm1079 Před rokem

    Great Work James

  • @Moosa_Says
    @Moosa_Says Před rokem +1

    Thanks man i didn't know about Command.IsRunnig. It will be really helpful :)

  • @ajonescouk
    @ajonescouk Před rokem +2

    For those saying that VS doesn't work well with code generators, if you can afford it I've switched to Rider and my experience with generators is pretty good.

  • @paulegan3783
    @paulegan3783 Před rokem +1

    Thanks!

  • @guilla5
    @guilla5 Před rokem

    Hello James, Long time follower here. I tried using community toolkit in my company's product, which I can't disclose due to an NDA, and found difficulties implementing it but with these changes, I believe we will be able to do so easily.
    Thanks for so much awesome content

  • @Meisme1834
    @Meisme1834 Před rokem +1

    Hello James, this was incredibly helpful as I'd been forced to abandon [ObservableProperty] for public Get; Set; to allow the use of conditional code. Now I can use the partial override to trigger when changed! Awesome!
    If you need an idea for content, it would be SUPER helpful to learn how to execute EVENTS for CONTROLS on the VIEW via the VIEWMODEL using the MVVM design. I've been scouring all the documentation but can't find any documentation. Hitting a bit of a dead-end, without putting the events in the XAML backing code. Just as an example, if I want to execute a "HandlerChanging" on an "Editor" control, right now I have to put the code in the backing code, but the backing code can't access the VIEWMODEL, thus I'm still stuck.
    Anywho, thanks for all your videos. They've been a tremendous help!

  • @emmanueladebiyi2109
    @emmanueladebiyi2109 Před rokem

    Amazing!

  • @dotnetdevni
    @dotnetdevni Před rokem

    Source Gnerators have come along way I remmber u had to embed ur csharp code as a stirng this is looking promising

  • @BkWDrums
    @BkWDrums Před rokem

    I migrated my app from Prism to MVVM toolkit and it's honestly great. The only thing I miss is Prism's region manager. It's just a shame Visual Studio kinda sucks when it comes to source generators

  • @adiazwise
    @adiazwise Před rokem

    Hi James great video , I have a question , is possible to call a relaycommand when a query property is received from another view model?

  • @westebo6748
    @westebo6748 Před rokem

    Are there any issues or pitfalls with using the ObservableProperty with a model instead of direct bindings? What if instead of binding to FirstName and LastName as you do in your example, you wanted use the source generators and bindings to bind to Person.FirstName and Person.LastName?

  • @gregmartin7752
    @gregmartin7752 Před rokem +1

    Hey James, what is the reasoning and pros and cons for using source generators and partial classes, versus IL weaving?

    • @JamesMontemagno
      @JamesMontemagno  Před rokem +1

      Basically precompiled vs manipulating the compiled DLL. All of the intellisense is available and you have access to items ahead of time and can see the code compared to weaving. Both have their advantages and disadvantages.
      Generating source code also lets you create things such as these partial methods and other things that devs can use when coding

  • @vm123
    @vm123 Před rokem +2

    Is it just me? I'm getting false positive syntax errors all the time (mainly CS0117 'ApplAdminViewModel' does not contain a definition for 'FileDeleteCommand'), the editor underlines red generated commands and properties, but project does compile. It happens almost all the time, making whole project completely unreadable making the whole tool useless (although the source generation idea is brilliant). Anyone else experiencing same crashes?
    Using latest version of VS 2022 preview community edition, small winforms project (few forms + vms).

  • @sinsedrix
    @sinsedrix Před rokem +1

    Wow ! If you need ActivityIndicator to be visible for many running command, is there a specific trick?

  • @ErwinEchon
    @ErwinEchon Před rokem

    Hi James, do you have a video for login using .Net Maui and MVVM?. thank you in advance. I love your videos.

  • @ThorstenSchmitz-dq9os

    Very cool. What I would like to know, is there a way to use add code for validation? E.g. to make sure the users input is a valid email address or date?

    • @JamesMontemagno
      @JamesMontemagno  Před rokem

      Yes! The toolkit has validation built in but of course will vary based on how you want the ui to react. You can also loop into the change events as well like I showed

    • @ThorstenSchmitz-dq9os
      @ThorstenSchmitz-dq9os Před rokem

      @@JamesMontemagnoThat's great, but as far as I understand the docs, all of this is either executed after the change event is triggered or, in case of the changing event, doesn't affect the change. So I can't validate it before changing the property and stop it from generating a change event. I would have to change it back in my method ang thus get a 2nd change event, right?

  • @yaser107
    @yaser107 Před rokem

    hi james thanks for your great vidoes i have an error when i add [relaycommand] on any void this is the error viewmodel already contains a definition for "command name"
    i have searched for the error it is source generation run twice do you have any idea how to fix it

    • @JamesMontemagno
      @JamesMontemagno  Před rokem

      Hmmm do you have a source code reference? See what was actually generated. I have had it one time where I accidentally called things the same and didn’t realize

  • @squan888
    @squan888 Před rokem

    Does the CommunityToolkit do anything when you implement FirstName + LastName in one ViewModel but FullName in another ViewModel is there a way with attributes to bubble on PropertyChanged events from one ViewModel to the other?

    • @JamesMontemagno
      @JamesMontemagno  Před rokem

      Across viewmodels you probably need to use a messenger service

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

    What is that setting in Visual Studio that made the "inherited" or "External Assembly" rainbow colored? 8:59

  • @chrislamont7529
    @chrislamont7529 Před rokem

    Hey James, Super nice feature, but looks like I can't unit test any of this as "firstName" is a private field and the generated code is not generated until it is compiled. Any ideas how this can be done?

    • @JamesMontemagno
      @JamesMontemagno  Před rokem +1

      Source generators are generated when the project is open or compiled so you can write your tests against it just fine from my experience.

    • @chrislamont7529
      @chrislamont7529 Před rokem

      @@JamesMontemagno Nice, after compiling I can now access the properties 👍

  • @adinwashere
    @adinwashere Před rokem

    What if I want to load data when the page comes up? Where to I put my Async calls?

  • @nevering5222
    @nevering5222 Před rokem

    how about a desktop app video ? will Maui work for robust desktop apps ?

  • @user-ds1sp8wt1u
    @user-ds1sp8wt1u Před rokem

    After a few days of work, my compiler started showing a "method does not exist" error because it is automatically generated by this toolkit.
    The app is working! But the compiler shows a lot of errors...
    Go back to plain RelayCommand and full properties :(

  • @GIMMY2K1
    @GIMMY2K1 Před rokem

    Where i ca find the convention for a good work.
    For example:
    'LoginCommand' in XAML ( Command="{Binding LoginCommand}")
    must be 'Login()' method in viewModel ( without postfisso 'command'
    ( [RelayCommand]
    private async Task Login() )
    Is it true ?

  • @user-rz1hv
    @user-rz1hv Před rokem

    Hi, what's the music plays at the end of the video?

    • @user-rz1hv
      @user-rz1hv Před rokem

      found, it's RisingFades by "StreamBeats by Harris Heller"

    • @JamesMontemagno
      @JamesMontemagno  Před rokem +1

      Yup! That is the one!!! Good old Harris Heller :)

  • @NotInventedHereShow
    @NotInventedHereShow Před rokem

    The [property: Xxx], is that a new language feature?

  • @michael36923
    @michael36923 Před rokem +1

    Tried v8.0 source generators with a .NET Framework 4.8.1 WPF app but didn't get it working.
    My research resulted in .NET Framework 4.x does not support source generators.
    You mentioned it is indeed working?! Please tell me how! :-)

    • @hwod44
      @hwod44 Před rokem

      I also had several problems with CT mvvm with WPF + Net Framework. It doesn't support really well the CommandManager for RelayCommands with Buttons. I also tried to migrate WPF with Net Core and this Toolkit but It doesn't work well too...

    • @JamesMontemagno
      @JamesMontemagno  Před rokem

      I have a sample in my GitHub repo I link to. You have to put your code in a .net standard library. You have to be using the new sdk style projects

  • @stasasekulic6917
    @stasasekulic6917 Před rokem

    This is not working with objects and navigations....

    • @JamesMontemagno
      @JamesMontemagno  Před rokem +1

      Hmmm I have not seen any issues. I did it yesterday in my workshop

    • @stasasekulic6917
      @stasasekulic6917 Před rokem

      @@JamesMontemagno Here is the code, I have done it as I answered, but I am not sure if it's correct way. How can I get notified for workshop? :)

  • @Ryochan7
    @Ryochan7 Před rokem +1

    Not if you care about app performance. Most .NET devs don't care though