CanExecuteChanged doesn't fire
See original GitHub issueHello!
Thank you very much for your solution!
I tried “simple” version from https://johnthiriet.com/mvvm-going-async-with-async-command/#
But I faced a problem that I solved without understanding…
The issue is CanExecuteChanged didn’t fire on ObservableCollection change. I tried
collection.CollectionChanged += (sender, e) => CalculateAsync.RaiseCanExecuteChanged();
But nothing happened.
So the only way I found is to remove the following method
public void RaiseCanExecuteChanged() { CanExecuteChanged?.Invoke(this, EventArgs.Empty); }
from your code and replace
public event EventHandler CanExecuteChanged;
with
public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } }
I’m new with all these things, so I don’t really understand what I have changed. It works now but seems with kind of delay in releasing the button after a command
If you have a minute, can you please explain the correct way of fixing my problem, please.
Thanks in advance
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
@brminnick thank you very much for your help with code and explanation! 😃 I really appreciate it!)
And thanks so much for the feedback!
I’ve updated the docs to include an example of
CanExecuteChanged
:https://github.com/brminnick/AsyncAwaitBestPractices/blob/master/README.md#asyncawaitbestpracticesmvvm-2