Even More MVVM Source Generator Awesomeness for .NET Developers

2024 ж. 15 Мам.
26 040 Рет қаралды

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

Пікірлер
  • Thank you James We are waiting for more videos about MAUI from you

    @deaasaleh3613@deaasaleh3613 Жыл бұрын
  • Thanks for this video. Having the option to add Json-Properties is really the one thing I was missing in Release 8.

    @berlinerffm@berlinerffm Жыл бұрын
  • That is very amazing 👏 like i really love the community toolkit right now and it will be a must in any of my projects

    @goldenwolf2621@goldenwolf2621 Жыл бұрын
  • I've been using it wirh AvaloniaUI since your first video. I absolutely love it ! My fingers are so thankful !

    @MaximilienNoal@MaximilienNoal Жыл бұрын
  • 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....

    @glenmackay6539@glenmackay6539 Жыл бұрын
  • 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!

    @bkaankose@bkaankose Жыл бұрын
  • Great Work James

    @maxm1079@maxm1079 Жыл бұрын
  • 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!

    @yvanbrunel9734@yvanbrunel9734 Жыл бұрын
  • Thanks man i didn't know about Command.IsRunnig. It will be really helpful :)

    @Moosa_Says@Moosa_Says Жыл бұрын
  • Great video James!! 🌞🌞🌞🌞🌞🌞

    @sheilainglin863@sheilainglin863 Жыл бұрын
  • +1 for "plethora"

    @CarminaIguana@CarminaIguana Жыл бұрын
  • 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!

    @Meisme1834@Meisme1834 Жыл бұрын
  • 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

    @guilla5@guilla5 Жыл бұрын
  • Hi James great video , I have a question , is possible to call a relaycommand when a query property is received from another view model?

    @adiazwise@adiazwise Жыл бұрын
  • Thanks!

    @paulegan3783@paulegan3783 Жыл бұрын
  • Amazing!

    @emmanueladebiyi2109@emmanueladebiyi2109 Жыл бұрын
  • 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.

    @ajonescouk@ajonescouk Жыл бұрын
  • Source Gnerators have come along way I remmber u had to embed ur csharp code as a stirng this is looking promising

    @dotnetdevni@dotnetdevni Жыл бұрын
  • 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

    @BkWDrums@BkWDrums Жыл бұрын
  • Hi James, do you have a video for login using .Net Maui and MVVM?. thank you in advance. I love your videos.

    @ErwinEchon@ErwinEchon Жыл бұрын
  • What is that setting in Visual Studio that made the "inherited" or "External Assembly" rainbow colored? 8:59

    @g4yktzgjx6@g4yktzgjx66 ай бұрын
  • 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?

    @westebo6748@westebo6748 Жыл бұрын
  • Wow ! If you need ActivityIndicator to be visible for many running command, is there a specific trick?

    @sinsedrix@sinsedrix Жыл бұрын
  • Hey James, what is the reasoning and pros and cons for using source generators and partial classes, versus IL weaving?

    @gregmartin7752@gregmartin7752 Жыл бұрын
    • 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

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • how about a desktop app video ? will Maui work for robust desktop apps ?

    @nevering5222@nevering5222 Жыл бұрын
  • The [property: Xxx], is that a new language feature?

    @NotInventedHereShow@NotInventedHereShow Жыл бұрын
  • 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?

    @ThorstenSchmitz-dq9os@ThorstenSchmitz-dq9os Жыл бұрын
    • 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

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • @@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?

      @ThorstenSchmitz-dq9os@ThorstenSchmitz-dq9os Жыл бұрын
  • What if I want to load data when the page comes up? Where to I put my Async calls?

    @adinwashere@adinwashere Жыл бұрын
  • 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

    @yaser107@yaser107 Жыл бұрын
    • 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

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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?

    @squan888@squan88810 ай бұрын
    • Across viewmodels you probably need to use a messenger service

      @JamesMontemagno@JamesMontemagno9 ай бұрын
  • 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 :(

    @user-ds1sp8wt1u@user-ds1sp8wt1u Жыл бұрын
  • 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?

    @chrislamont7529@chrislamont7529 Жыл бұрын
    • Source generators are generated when the project is open or compiled so you can write your tests against it just fine from my experience.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • @@JamesMontemagno Nice, after compiling I can now access the properties 👍

      @chrislamont7529@chrislamont7529 Жыл бұрын
  • 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).

    @vm123@vm123 Жыл бұрын
  • 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 ?

    @GIMMY2K1@GIMMY2K1 Жыл бұрын
    • Yes!

      @MarcosAriel-hl6ts@MarcosAriel-hl6ts9 ай бұрын
  • Hi, what's the music plays at the end of the video?

    @user-rz1hv@user-rz1hv Жыл бұрын
    • found, it's RisingFades by "StreamBeats by Harris Heller"

      @user-rz1hv@user-rz1hv Жыл бұрын
    • Yup! That is the one!!! Good old Harris Heller :)

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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! :-)

    @michael36923@michael36923 Жыл бұрын
    • 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...

      @hwod44@hwod44 Жыл бұрын
    • 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

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • This is not working with objects and navigations....

    @stasasekulic6917@stasasekulic6917 Жыл бұрын
    • Hmmm I have not seen any issues. I did it yesterday in my workshop

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • @@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? :)

      @stasasekulic6917@stasasekulic6917 Жыл бұрын
  • Not if you care about app performance. Most .NET devs don't care though

    @Ryochan7@Ryochan7 Жыл бұрын
KZhead