Mvvm icon indicating copy to clipboard operation
Mvvm copied to clipboard

How to use AsyncCommand canExecuteChangedFactory?

Open RedX2501 opened this issue 4 years ago • 3 comments

I'm trying to use pre3 and it seems that I cannot pass a simple function any more as the the second parameter for the AsyncCommand as you have suggested here: https://github.com/StephenCleary/Mvvm.Async/issues/11#issuecomment-259687116

What is the expected way of using the factory in pre3 release?

RedX2501 avatar Dec 06 '19 06:12 RedX2501

The factory is a specific implementation of the CanExecuteChanged event (not it's logic).

The current AsyncCommand class always ties CanExecute to IsExecuting. If you need different logic, you'd need to derive a custom type from AsyncCommandBase.

Hope this helps, -Steve

StephenCleary avatar Dec 06 '19 23:12 StephenCleary

Thanks for the hint. I didn't understand that from the comments.

So this means that if a command shall only execute on a certain pre-condition you would expect a new property to be introduced and that bound to the IsEnabled property in the XAML?

bool CanExecuteCommandX => !AsynCommandGenerateX.IsExecuting && otherCondition

That seems overly cumbersome and against most examples and books about WPF and the Command parameter.

RedX2501 avatar Dec 07 '19 07:12 RedX2501

It's overly cumbersome and sort of against the idea of even taking delegate arguments if I have to derive a new type to support CanExecuteChanged.

Extant conversations and StackOverflow discussions seem to indicate the OnCanExecuteChanged() method used to be public. Why did it change to protected?

SittenSpynne avatar Dec 16 '19 22:12 SittenSpynne