I have bound button command to one RelayCommand from MVVM Toolkit, which executes some function, with folllowing:
[RelayCommand]
private async void SomeMethod() {}
I want to prevent multiple click on the button hence,preventing multiple method calls via CanExecute parameter of RelayCommand, but I can't figure that one out.
I know that RelayCommand first checks with CanExecute if it is possible to execute command, but I do not understand how to go about implementing it.
I have searched numerous questions on the topic, but could get no where near to solution.
Edit: Also there is no SomeMethod.isRunning property.
CodePudding user response:
You just need to change void to Task.
[ObservableObject]
public partial class MainWindowViewModel
{
[RelayCommand]
private async Task SomeMethod()
{
await Task.Delay(5000);
}
}
