Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CanExecute in RelayCommand MVVM Toolkit

I have bound button command to one RelayCommand from MVVM Toolkit, which executes some function, with following:

[RelayCommand]
private async void SomeMethod() {}

I want to prevent multiple clicks 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 the command, but I do not understand how to go about implementing it.

I have searched numerous questions on the topic but could get nowhere near to solution.

Edit: Also there is no SomeMethod.isRunning property.

like image 327
Guezt Avatar asked Apr 20 '26 18:04

Guezt


1 Answers

To implement CanExecute, You can try the following example:

[RelayCommand(CanExecute = nameof(IsSomeMethodExcutable))]
private async void SomeMethod(){}

private bool IsSomeMethodExcutable() { return _isBusy;}
like image 147
hugebug4ever Avatar answered Apr 22 '26 17:04

hugebug4ever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!