In my view models, I wanted to use the source generators in CommunityToolkit.Mvvm but for some reason I can't seem to use [ICommand]
attribute with my action methods.
The error I get is:
Cannot apply attribute class 'ICommand' because it is abstract
Here's the base class for my view model model.
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp.ViewModels
{
public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
bool isBusy = false;
[ObservableProperty]
string title = string.Empty;
}
}
And here's my view model class:
public class MyViewModel : BaseViewModel
{
[ObservableProperty]
string firstName;
[ObservableProperty]
string lastName;
[ICommand] // <-- This is where I get the error I mentioned above
async Task DoSomething()
{
// Do something here...
}
}