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...
}
}
[ICommand]
with[CommunityToolkit.Mvvm.Input.ICommand]
and see if that was the case. – ChigoeSystem.Windows.Input
but I don't findICommand
inCommunityToolkit.Mvvm.Input.ICommand
. I'm using version8.0.0-preview4
. The only thing I see in there isRelayCommand
but that I can't seem to use it as an attribute and it doesn't work in the above example. – Canonist