There have been several updates to the library and name changes for the properties, so check out github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0 for changes
Hi! Idk if you can help me on one thing. When I create a [ObservableProperty] of anything (string, ObservableCollection etc) the binding work perfectly. When I create a [ObservableProperty ] of a Model, i can't get the ui to update...I really don't get it. When I debug my Model.Properties get updated, but the ui dont. I try UpdateSourceTrigger=PropertyChanged, OneWay, TwoWay etc on the view. Nothing works. Thanks
This is so awesome! One of the hurdles of understanding and effectively using MVVM was getting your head around all the boilerplate plumbing code and understanding why it's needed. I always thought to myself "why can I just specify properties and commands and let the compiler do all the ceremony?" Yay! It finally happened!
This is beyond awesome! Super easy to implement. Makes your code soooo lean and easy to read. I love how you can use the code generation where you want to and still go the long route if you need to do stuff in your Get or Set. Excellent code! And a great video showing how to use it!
Shout out to James! You continue to help me up my game. This MVVM source generator is awesome and I look forward to more updates on recent developments.
MIND BLOWN! I love this with a passion. This helps reduce stupid errors both in initial creation and going back and modifying. This is awesome. I've used code generators in the past and I love them, but this is next level. Thanks again James!
You said it: it's ridiculously awesome. I've been working with WINUI 3 and i can see some differences that could be tricky for a newbie like me, but in the road we learn. Thanks James.
Listening to James makes me think of those old grow hair potion salesmen: " Well James, you wrote the ISync command, now What if you want to sink the Submit button and make it sing the song?" James:"Well you just need to carry the CommunityDev boilerplate which comes with the Generator..". Thanks for the the very interesting presentation James though! I like it 🙃😉
Wow, at last all that tons of lines went away... Keep those in just (a little few) attributes (not towers) thogh Maybe with a comma we'll avoid attributes towers. Great video!😎 James.
I am with you. I created a source generator for MVVM 7 years ago, and since then I stopped writing a lot of a code. Everything is done by the source generator. Continue to propagate the idea.
How many juniour developers could understand and extend on your code without wondering about black magic and stuff? D: I am very very cautious every time I see some work being done in background by some sort of extensions or dynamic code generation or self invented conventions nobody else in the world knows about. One thing is to rely on ms own attributes and conventions with tons of documentation and tests and usage and another is thinking that I am able to create, support and fix this on my own and that when I quit the job the next guy will know what the hell is happening in the code
@@ostelaymetaule It is a very good concern and actually I had a fear that simply developers will run away. But to my surprise, a feedback was completely opposite. They gladly started using it. Why? If system is designed well, it is so natural and intuitive, developers on any level, especially juniors, just use it.
@@kamertonaudiophileplayer847 I am glad to hear you managed to make it work, I have seen couple examples earlier in my career as well, but also encountered some over engineered magic bazoongas nobody knows what it does and the original dev is long gone ;)
@@ostelaymetaule It is normal, we lost several good developers exactly for the reason. Some system for some reason wasn't designed by us well. The result was really disappointing, we started loosing people because they simply can't use the system. Solution? Do not be afraid of to redesign the system instead of trying to fix it little by little.
Hi James, Great content and thank you for bringing this to my attention, seems to work perfectly in your demo. Small question: You had an example with the asynchronous command. Will the binding still work if I postfix the name of the method to 'SubmitAsync'? Or does the generated binding only work, because the name is 'Submit' for the method and 'SubmitCommand' in the Xaml?
Sweet! I use base classes to do some of that but it is not a lovely as using the attributes with the generators. The new code feels right and clean. Chunky boilerplate code has always felt dirty
I keep getting "the namespace for AlsoNotifyChangeForAttribute could not be found" Error when I try using AlsoNotifyChangeForAttribute in my view model property
@@JamesMontemagno Oh! thank you, I thought I had broken something somewhere Are you aware if there have been any fixes on the .Net SDK bug that duplicates source generators on-build?
Hey James. You can do this for many years using propertychanged.fody nuget package. What is even better it can do this without all those attributes. Especially combined values like Full name from your example. You can use them directly without specifying that it should be updated in other properties attribute. The thing about ICommand is quite neat in your presentation, this is currently not present in propertychanged.fody But also it's quite small price to pay in comparison with all the boilerplate code for properties. On a side note. Keep up the good work. I was using many packages of yours for few years already. Thank you for every single one of them. Cheers
I should have talked a bit about fody a bit in there. It is more assembly weaving to manipulate IL from my understanding. Where this is source generators where they are generated instantly without compilation. Correct me if I am wrong.
@@JamesMontemagno You're right. Despite fody adding zero boilerplate, you do not have access to the generated code, because its generated at compile time. With source generators, you can see in real time all the code that is generated which is awesome in my opinion and gives us the opportunity to learn new things by exploring the generated code.
@@JamesMontemagno I think the source generator might not be mature enough at this time. It sometimes bring in strange issues and I should reload the project for fixing it. Hope MSFT can make this tool much better.
@@JamesMontemagno as Luiz said, you are absolutely right. Source generators have other benefits, but also propertychanged.fody gives you the same outcome with cleaner code (no attributes needed). Also I don't remember if I ever needed to inspect the code that got generated. In most cases it's quite simple. Would it be possible to use source generators without those attributes?
It's a great idea. Since I'm a WinForms guy I keep sliding back to it because it's so simple and I can write stuff fast and clean. I tried MVVM again on my latest Xamarin application (since WinForms was not an option) but still ended up using mostly code behind because I found all the MVVM stuff just too hard to keep track of and getting it to work cleanly with the UI was just too daunting. If these people can make it less complicated that would be great. I DID find the code it generated very scary looking though. If I get some bizarre error about eyepoke() not properly initialized or the my app just hanging or disappearing I would probably give up and go simple again.
While I've gotten used to MVVM in WPF, at the end of the day I'm still not convinced it is actually nearly as good a pattern as the head-in-the-clounds programers make it out to be. The reality of my (and I think many others) is simply not at the scale where we really profit from it. Back when we switched to it, it was sold with the promises of having the option to easily outsource the view design (because of the decoupling), being unit testable and being oh-so-efficient. After working with it for years, I have to say that I still end up writing most if not all of my view code myself. I have barely written any unit tests, because the stuff that actually fails is way to much effort to unit test and the simple stuff I have clicked through quicker than I've set up the test. And lastly I don't think having to do 3 things to handle a button event or drowning in property boilerplate code has made the code any more readable or quicker to produce. The tiny bit of intellisense support you get from it hardly makes it worth it imho. I know there are plenty of nugets and extension to help with this and we've used a couple of them mostly successfully over the years, but it never really felt like at the base the effort was worth it That being said, seeing this auto code generation I feel like we've finally reached a the point where the extra effort has been reduced to a level that no longer negates all the smaller benefits (I will probably still not write alot of unit tests or have some of those mythical html programmers swoop in and design beautiful GUIs for me :P). I just wish I could actually use it in all the older projets we still have to maintain, but sadly they are still mostly on .Net4.7. Well at least going forward it will become alot nicer.
Thank you James for really nice video.. One suggestion, could you please create video on DeepLinking where application can launch from url like Amazon...
Great video, as usual, James. Couple quick questions: How do we pass command parameters? Does it function inside of VS 2019? Sometimes we have to drop back to use the MultiLingual extension, since it's not in VS 2022.
You can pass command parameter through whatever system the UI framework you're using has, that's separate from the command implementations the MVVM Toolkit has (for instance, on WPF/UWP/WinUI you'd do CommandParameter="{Binding ...}", or {x:Bind ...}, etc.). As for VS2019, no the generators will not work there. For the 8.0.0 release of the MVVM Toolkit I've rewritten all of them to be incremental generators, and that feature needs Roslyn 4.x to work, which isn't available on VS2019. You'll need VS2022 for that (or another modern IDE of your choice, eg. Rider). Hope this helps!
Checkout github.com/CommunityToolkit/dotnet/issues/158 for a working sample, You will need to put things in a .NET Standard library for it to fully work.
Good question, checkout the blog for sure -> devblogs.microsoft.com/ifdef-windows/announcing-net-community-toolkit-v8-0-0-preview-1/ You can do -> [AlsoNotifyCanExecuteFor] on a property
Thank you for the awesome video, could you make a video how to use Messengers with the toolkit? And a video for navigation would be also very nice. Thank you!
Hi James. This is pretty awesome. The pattern with the if(SetProperty(...)) { ... } is not new to me, I've been using that already for a while now since MvvmLight allowed me to do the same thing, except for the code generation part of it. Does this mean that we can reuse our ViewModels and share them between Xamarin/MAUI and WPF applications? Does the new Community Toolkit also include ICommand derivatives and implementations for IAsyncCommand like the Xamarin Community Toolkit does? BTW, I absolutely love that we can update the canExecute flag of Commands using attributes now, it takes away a lot of messy code pain.
Hi James, I love your tutorials. I've been diving a bit deeper into the MMVM Toolkit as I steadily replace my old MVVMLight code. One area not covered in your video that I'd like some more insight into is the ICommand "RaiseCanExecuteChanged". I'm seeing things like [NotifyCanExecuteChangedFor] in the new Toolkit that looks promising. Do you have a video that covers this or can you point me somewhere that might? Thanks so much.
@@JamesMontemagno I can get the ObservableProperty to work after changing to C# 9 in Xamarin Forms. Can't get the ICommand to work, the method is never called. Ver 8.0 preview2.
hey James, awesome video as always, one question sits on my mind, how does this work with the xamarin community toolkit and the future MAUI community toolkit, as I see some overlapping bits, thx!
So they are all on the same GitHub organization now and are aligned. The genera .NET one will focus on full compatibility with all .NET apps and then the individual one will be specific to the frameworks and they are working on minimizing any overlap
@@JamesMontemagno awesome thx for the answer, I really like the code generated stuff but I would like to use the xamarin / Maui community toolkit as well and not have to worry about using the wrong namespace :D
It isn’t a framework at all just helpers. Not sure what you are building with and for our what problems what you are having but would love to learn. Reach out on twitter
@@JamesMontemagno just hard to set up navigation in mvvm..it’s not too bad when you have a simple UI, just when you’re UI is a little different and you need communication between viewmodels.. was hoping that it would have a little framework behind it instead of just helpers.
Thanks, James. I haven't been a fan of magic source generators for awhile. I have been using a library of my own with all the necessary boilerplate. This could simplify things and reduce the number of keystrokes needed. However, I did run into one problem. I have a BaseViewModel for may pages with things like the page title and analytics services common to all page view models in my project. The source generator stops generating code as soon as I inherit from BaseViewModel. Without the base view model, I have to type (or copy paste) just as much code as is eliminated by the source generator. Thus not much of a win for me in total. I suppose I could trick this systems and add the inheritance at the end, but I'm sure I'll forget in a year when I add a new property to the view model. Is there a better workaround for this scenario?
Hmmmmm this should totally work as I do this in the workshop I am working on.... not sure why it wouldn't work.... If you have a sample repo send it over to me via twitter or email so I can look
Hey James, great video! Do you know if it's possible to call a method on a property change? Say FirstName changes and I want to call a method where I use the new value. It would be awesome if there would be something like [CallOnPropertyChange(Action action)]
Hey there! Yes, you can do this as well. In the new 8.0.0-Preview2 version (we released it just this Thursday), the ObservableProperty generator also generates two partial methods: OnPropertyChanging and Changing (the name will match the one of that property). You can define them in your code and from there execute all custom logic if needed. The cool thing is that if you don't, those methods are just removed entirely from the compiler, so there's no overhead at all. Basically just do this: [ObservableProperty] private string name; partial void OnNameChanged(string value) { Console.WriteLine($"Hello {value}!"); } Hope this helps! I'll be including all this in a proper blog post once we ship 8.0.0 for good 😄
great stuff for MVVM , one questions i am having like if we have more than 1 button how can we distinguish with this? Whether name of method will be same as ICommand mentioned in Xaml?
There have been several updates to the library and name changes for the properties, so check out github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0 for changes
This comment saved my day :) Thanks James!
Hi! Idk if you can help me on one thing. When I create a [ObservableProperty] of anything (string, ObservableCollection etc) the binding work perfectly.
When I create a [ObservableProperty ] of a Model, i can't get the ui to update...I really don't get it.
When I debug my Model.Properties get updated, but the ui dont. I try UpdateSourceTrigger=PropertyChanged, OneWay, TwoWay etc on the view. Nothing works.
Thanks
Cheers!
Wow, finally something that fixes my biggest gripe with xaml MVVM development. Thx James!
Makes the code so much cleaner, and easier to understand for others.
This is so awesome! One of the hurdles of understanding and effectively using MVVM was getting your head around all the boilerplate plumbing code and understanding why it's needed. I always thought to myself "why can I just specify properties and commands and let the compiler do all the ceremony?" Yay! It finally happened!
Great tutorial, Thanks James.
Amazing. This just made WPF applications 100 times easier. Thanks for the great video.
You're welcome!
This is beyond awesome! Super easy to implement. Makes your code soooo lean and easy to read. I love how you can use the code generation where you want to and still go the long route if you need to do stuff in your Get or Set. Excellent code! And a great video showing how to use it!
Glad you like it!
Shout out to James! You continue to help me up my game. This MVVM source generator is awesome and I look forward to more updates on recent developments.
Love to see the excitement in your own expressions, tells you how great it is !
I was stuck with mvvm since 2010. Now, I finally love it.
MIND BLOWN! I love this with a passion. This helps reduce stupid errors both in initial creation and going back and modifying. This is awesome. I've used code generators in the past and I love them, but this is next level. Thanks again James!
🎉🎉🎉
Great, great, great. And as usual, brilliantly described. Nice work James & team.
You said it: it's ridiculously awesome. I've been working with WINUI 3 and i can see some differences that could be tricky for a newbie like me, but in the road we learn. Thanks James.
Wow simply wow! The MCT.MVVM was already very helpful but this is incredible!
Listening to James makes me think of those old grow hair potion salesmen:
" Well James, you wrote the ISync command, now What if you want to sink the Submit button and make it sing the song?"
James:"Well you just need to carry the CommunityDev boilerplate which comes with the Generator..".
Thanks for the the very interesting presentation James though! I like it 🙃😉
Awesome! I just tried this against OpenSilver and it works GREAT!
Wow, at last all that tons of lines went away... Keep those in just (a little few) attributes (not towers) thogh
Maybe with a comma we'll avoid attributes towers. Great video!😎 James.
My mind IS blown James! Thank you!
Thanks James! Amazing and easily broken down. Definitely applying this
That is absolutely amazing! Thanks!
Top notch! Nice work.
Wow... Game changer. Kudos to all involved. Can't wait to start using it. Thanks for the video James 👍
Really great addition to the community toolkit! Thanks a lot for the tutorial.
Glad you like it!
Yes, this would be my 1st personal choice among others mmvm library out there !! Thanks a bunch
The best MVVM content creator ever thanks james.
This is really great. Thanks for posting.
Glad you enjoyed it!
Truly an awesome library
James, thank you for this video. I wrote so much code over the last years, that I can now delete. - Just a joke. I definitely check this out!
This is awesome! Very clever implementation.
Many thanks to you James. This is really helpful and blowing my mind too 🤯🤯🤩.
Amazing that is what I wanted
Coz I am lazy :)
🤣🤣🤣🤣
Such a great tool :) thx for sharing!!!!
Thanks so much James, very nice
Game changer! Can't wait to get stuck in!
My mind was blown james, when you decorated the private fields with ObservableProperty
Awesome... Like it so much. 😍😍😍👍👍👍
Yet again James is here to save the day for devs and students, thanks man.
This is honestly pretty amazing!
wow James, you are amazing. You showed my so many cool nugets, that make my life easier. Thank you very much !
Very useful. I was doing everything code behind. Now i will try this.
MVVM is now practical with this
wow, how many things are change. Thank jame
Thanks James, you really treasure
very good this! James
This is awesome. Thanks James.
Looks like the future to me James..!
Awesome, thank you very much. Now I am on the hunt for some good tutorials how to create such generators by myself 🙂.
Great tutorial !!!
This is so good, that it makes me wonder why this wasn't there with the release of WPF.
Thank you so much James
Super useful ! Thanks 👍
Hooo, I need to update my projects right now!!
VERY cool! Thanks for sharing!
I am with you. I created a source generator for MVVM 7 years ago, and since then I stopped writing a lot of a code. Everything is done by the source generator. Continue to propagate the idea.
How many juniour developers could understand and extend on your code without wondering about black magic and stuff? D: I am very very cautious every time I see some work being done in background by some sort of extensions or dynamic code generation or self invented conventions nobody else in the world knows about. One thing is to rely on ms own attributes and conventions with tons of documentation and tests and usage and another is thinking that I am able to create, support and fix this on my own and that when I quit the job the next guy will know what the hell is happening in the code
@@ostelaymetaule It is a very good concern and actually I had a fear that simply developers will run away. But to my surprise, a feedback was completely opposite. They gladly started using it. Why? If system is designed well, it is so natural and intuitive, developers on any level, especially juniors, just use it.
@@kamertonaudiophileplayer847 I am glad to hear you managed to make it work, I have seen couple examples earlier in my career as well, but also encountered some over engineered magic bazoongas nobody knows what it does and the original dev is long gone ;)
@@ostelaymetaule It is normal, we lost several good developers exactly for the reason. Some system for some reason wasn't designed by us well. The result was really disappointing, we started loosing people because they simply can't use the system. Solution? Do not be afraid of to redesign the system instead of trying to fix it little by little.
Hi James,
Great content and thank you for bringing this to my attention, seems to work perfectly in your demo.
Small question: You had an example with the asynchronous command. Will the binding still work if I postfix the name of the method to 'SubmitAsync'? Or does the generated binding only work, because the name is 'Submit' for the method and 'SubmitCommand' in the Xaml?
You changed my life, bro.
Cool that is too much life will be easy after using this Thank you JM
Sweet! I use base classes to do some of that but it is not a lovely as using the attributes with the generators. The new code feels right and clean. Chunky boilerplate code has always felt dirty
I keep getting "the namespace for AlsoNotifyChangeForAttribute could not be found" Error when I try using AlsoNotifyChangeForAttribute in my view model property
The final version introduces some new names github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0
@@JamesMontemagno Oh! thank you, I thought I had broken something somewhere
Are you aware if there have been any fixes on the .Net SDK bug that duplicates source generators on-build?
Hey James. You can do this for many years using propertychanged.fody nuget package.
What is even better it can do this without all those attributes. Especially combined values like Full name from your example. You can use them directly without specifying that it should be updated in other properties attribute.
The thing about ICommand is quite neat in your presentation, this is currently not present in propertychanged.fody
But also it's quite small price to pay in comparison with all the boilerplate code for properties.
On a side note. Keep up the good work. I was using many packages of yours for few years already. Thank you for every single one of them. Cheers
I should have talked a bit about fody a bit in there. It is more assembly weaving to manipulate IL from my understanding. Where this is source generators where they are generated instantly without compilation. Correct me if I am wrong.
@@JamesMontemagno You're right. Despite fody adding zero boilerplate, you do not have access to the generated code, because its generated at compile time. With source generators, you can see in real time all the code that is generated which is awesome in my opinion and gives us the opportunity to learn new things by exploring the generated code.
@@JamesMontemagno I think the source generator might not be mature enough at this time. It sometimes bring in strange issues and I should reload the project for fixing it. Hope MSFT can make this tool much better.
@@JamesMontemagno as Luiz said, you are absolutely right.
Source generators have other benefits, but also propertychanged.fody gives you the same outcome with cleaner code (no attributes needed). Also I don't remember if I ever needed to inspect the code that got generated. In most cases it's quite simple.
Would it be possible to use source generators without those attributes?
@@williamliu8985 Unfortunately, I had to find that out too.
Stunning beautiful
It's a great idea. Since I'm a WinForms guy I keep sliding back to it because it's so simple and I can write stuff fast and clean. I tried MVVM again on my latest Xamarin application (since WinForms was not an option) but still ended up using mostly code behind because I found all the MVVM stuff just too hard to keep track of and getting it to work cleanly with the UI was just too daunting. If these people can make it less complicated that would be great. I DID find the code it generated very scary looking though. If I get some bizarre error about eyepoke() not properly initialized or the my app just hanging or disappearing I would probably give up and go simple again.
While I've gotten used to MVVM in WPF, at the end of the day I'm still not convinced it is actually nearly as good a pattern as the head-in-the-clounds programers make it out to be. The reality of my (and I think many others) is simply not at the scale where we really profit from it. Back when we switched to it, it was sold with the promises of having the option to easily outsource the view design (because of the decoupling), being unit testable and being oh-so-efficient. After working with it for years, I have to say that I still end up writing most if not all of my view code myself. I have barely written any unit tests, because the stuff that actually fails is way to much effort to unit test and the simple stuff I have clicked through quicker than I've set up the test. And lastly I don't think having to do 3 things to handle a button event or drowning in property boilerplate code has made the code any more readable or quicker to produce. The tiny bit of intellisense support you get from it hardly makes it worth it imho. I know there are plenty of nugets and extension to help with this and we've used a couple of them mostly successfully over the years, but it never really felt like at the base the effort was worth it
That being said, seeing this auto code generation I feel like we've finally reached a the point where the extra effort has been reduced to a level that no longer negates all the smaller benefits (I will probably still not write alot of unit tests or have some of those mythical html programmers swoop in and design beautiful GUIs for me :P). I just wish I could actually use it in all the older projets we still have to maintain, but sadly they are still mostly on .Net4.7. Well at least going forward it will become alot nicer.
Great!! Thanks for sharing
Waw that's awesome thank you sir.
OMG this cool!
I actually made a post about "Why doesn't a system that generates the MVVM code for you!" in one of your older videos! Yes!
🎉🎉🎉🎉
An amazing tool I am using it for about a year -_-
Thank you James for really nice video..
One suggestion, could you please create video on DeepLinking where application can launch from url like Amazon...
Excellent video, and great topic, there is still a lack of video-content on Source Generators
Great video, as usual, James. Couple quick questions: How do we pass command parameters? Does it function inside of VS 2019? Sometimes we have to drop back to use the MultiLingual extension, since it's not in VS 2022.
I believe they should, but I only have 2022 on my machines now
You can pass command parameter through whatever system the UI framework you're using has, that's separate from the command implementations the MVVM Toolkit has (for instance, on WPF/UWP/WinUI you'd do CommandParameter="{Binding ...}", or {x:Bind ...}, etc.). As for VS2019, no the generators will not work there. For the 8.0.0 release of the MVVM Toolkit I've rewritten all of them to be incremental generators, and that feature needs Roslyn 4.x to work, which isn't available on VS2019. You'll need VS2022 for that (or another modern IDE of your choice, eg. Rider). Hope this helps!
Checkout github.com/CommunityToolkit/dotnet/issues/158 for a working sample, You will need to put things in a .NET Standard library for it to fully work.
Thanks for the great content. Can you please also make a video on MVVM Messaging?
Incredible tool! Thanks. How is Can Execute Command implemented?
+1
Good question, checkout the blog for sure -> devblogs.microsoft.com/ifdef-windows/announcing-net-community-toolkit-v8-0-0-preview-1/ You can do -> [AlsoNotifyCanExecuteFor] on a property
+1
I had same question myself...
[INotifyPropertyChanged]
public partial class MainWindowViewModel
{
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyCanExecuteFor(nameof(ShowCommand))]
private string firstName = string.Empty;
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyCanExecuteFor(nameof(ShowCommand))]
private string lastName = string.Empty;
public string FullName => $"{LastName} {FirstName}";
public bool CanShow { get => firstName.Length > 2 && lastName.Length > 2; }
[ICommand(CanExecute = nameof(CanShow))]
private void Show()
{
MessageBox.Show(FullName);
}
partial void OnFirstNameChanged(string value)
{
if (CanShow)
{
MessageBox.Show($"Execute Custom code on {value}");
}
}
}
XAML:
I like your plugin Media❤️
Fantastic video,!
Glad you liked it!
Thank you for the awesome video, could you make a video how to use Messengers with the toolkit? And a video for navigation would be also very nice. Thank you!
I wish a can give more than just a thumbs up, thats awesome!!!
INCREDIBLE 🙈
Awesome explanation, James! Thank you! Let me ask about obfuscation. Do you know if it works after obfuscating the code? I mean for a WPF app. Thanks!
Yes it does from my understanding, it is the same as if you wrote the code ;)
Hi James. This is pretty awesome. The pattern with the if(SetProperty(...)) { ... } is not new to me, I've been using that already for a while now since MvvmLight allowed me to do the same thing, except for the code generation part of it. Does this mean that we can reuse our ViewModels and share them between Xamarin/MAUI and WPF applications? Does the new Community Toolkit also include ICommand derivatives and implementations for IAsyncCommand like the Xamarin Community Toolkit does? BTW, I absolutely love that we can update the canExecute flag of Commands using attributes now, it takes away a lot of messy code pain.
It does, it included RelayCommand and AsyncRelayCommand or something like that, it is what it generates
@@JamesMontemagno that's awesome. Thanks! 😊
Fantastic!!!
Amazing stuff, thanks You very much! I'm writing a simple app for my team and i just can't wrap my head around how inefficient to write is WPF.
Is there a source generator or other clean way to add undo/redo functionality to the form in your example?
Hi James, I love your tutorials. I've been diving a bit deeper into the MMVM Toolkit as I steadily replace my old MVVMLight code. One area not covered in your video that I'd like some more insight into is the ICommand "RaiseCanExecuteChanged". I'm seeing things like [NotifyCanExecuteChangedFor] in the new Toolkit that looks promising. Do you have a video that covers this or can you point me somewhere that might? Thanks so much.
Excellent library, great video!
Does this also work for Xamarin Forms and WPF?
Yes it does!
I tried it but I get “This generator is not generating files…”
@@JamesMontemagno I can get the ObservableProperty to work after changing to C# 9 in Xamarin Forms. Can't get the ICommand to work, the method is never called. Ver 8.0 preview2.
I figured it out. I named my method ClickMeCommand and it did not work. I changed it to ClickMe and now it works.
Hi James, how can I implement an ObservableCollection using this method?
Thx James,
How can I use CanExecute for the Command function?
hey James, awesome video as always, one question sits on my mind, how does this work with the xamarin community toolkit and the future MAUI community toolkit, as I see some overlapping bits, thx!
So they are all on the same GitHub organization now and are aligned. The genera .NET one will focus on full compatibility with all .NET apps and then the individual one will be specific to the frameworks and they are working on minimizing any overlap
@@JamesMontemagno awesome thx for the answer, I really like the code generated stuff but I would like to use the xamarin / Maui community toolkit as well and not have to worry about using the wrong namespace :D
James, I am confused on this method, how do I add a Model to this? or does it all go in ViewModels?
This is awesome!
Thankyou for the video. Does the mvvm community toolkit make navigation easier?
It isn’t a framework at all just helpers. Not sure what you are building with and for our what problems what you are having but would love to learn. Reach out on twitter
@@JamesMontemagno just hard to set up navigation in mvvm..it’s not too bad when you have a simple UI, just when you’re UI is a little different and you need communication between viewmodels.. was hoping that it would have a little framework behind it instead of just helpers.
This is so cool 😎
It'll be very useful. What if we'd like to call a method when a property has changed?
Thanks, James. I haven't been a fan of magic source generators for awhile. I have been using a library of my own with all the necessary boilerplate. This could simplify things and reduce the number of keystrokes needed. However, I did run into one problem. I have a BaseViewModel for may pages with things like the page title and analytics services common to all page view models in my project. The source generator stops generating code as soon as I inherit from BaseViewModel. Without the base view model, I have to type (or copy paste) just as much code as is eliminated by the source generator. Thus not much of a win for me in total. I suppose I could trick this systems and add the inheritance at the end, but I'm sure I'll forget in a year when I add a new property to the view model. Is there a better workaround for this scenario?
Hmmmmm this should totally work as I do this in the workshop I am working on.... not sure why it wouldn't work.... If you have a sample repo send it over to me via twitter or email so I can look
@@JamesMontemagno I have the same problem - did you uncover a reason and/or solution? Thanks.
Fixed - my base class was using the wrong ObservableObject - from Xamarin.CommunityToolkit.ObjectModel instead of CommunityToolkit.Mvvm.ComponentModel
This is sweet.
Hey James, great video!
Do you know if it's possible to call a method on a property change?
Say FirstName changes and I want to call a method where I use the new value.
It would be awesome if there would be something like
[CallOnPropertyChange(Action action)]
Not sure, but open up a suggestion on GitHub
Hey there! Yes, you can do this as well. In the new 8.0.0-Preview2 version (we released it just this Thursday), the ObservableProperty generator also generates two partial methods: OnPropertyChanging and Changing (the name will match the one of that property). You can define them in your code and from there execute all custom logic if needed. The cool thing is that if you don't, those methods are just removed entirely from the compiler, so there's no overhead at all. Basically just do this:
[ObservableProperty]
private string name;
partial void OnNameChanged(string value)
{
Console.WriteLine($"Hello {value}!");
}
Hope this helps! I'll be including all this in a proper blog post once we ship 8.0.0 for good 😄
@@Sergio0694 I Had the same problem. Nice implementation.
Can you create some advanced tutorial on this? Navigation bar with views, commands and stuff?
Thanks for the video. Is it possible to do this with Blazor?
The library works everywhere, but Blazor doesn’t really use mvvm style databinding, it is just built in
great stuff for MVVM , one questions i am having like if we have more than 1 button how can we distinguish with this? Whether name of method will be same as ICommand mentioned in Xaml?
It is the name of the method and then they add Command. Checkout the source code sample. You can have as many ICommand as you need
Hey James what will be the effect of app size for large production app
None as it is all generated optimized code, nothing is happening at runtime. If anything maybe every performance gains due to optimizations.