question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CanExecuteChanged doesn't fire

See original GitHub issue

Hello! 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tyrgincommented, Nov 3, 2019

@brminnick thank you very much for your help with code and explanation! 😃 I really appreciate it!)

0reactions
brminnickcommented, Oct 30, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Relaycommand ICommand.CanExecute not firing
Relaycommand ICommand.CanExecute not firing · Difficult to say from your current code. · I'm only using thread/tasks for communication between my ...
Read more >
Pro WPF and Silverlight MVVM: Effective Application ...
The CanExecuteChanged event needs to fire whenever the CanExecute method ... Not only that, but the event is static, so the RelayCommand does...
Read more >
Usefulness of the Command CanExecute as it exists in WPF
The CommandManager will automatically call CanExecute to update the state of the button which means you don't need to manually track and fire...
Read more >
Pro WPF in VB 2010: Windows Presentation Foundation in .NET 4
It allows you to trigger the command, but it doesn't give you a way to ... When the CanExecuteChanged event fires, you need...
Read more >
Pro WPF 4.5 in VB: Windows Presentation Foundation in .NET 4.5
It allows you to trigger the command, but it doesn't give you a way to ... When the CanExecuteChanged event fires, you need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found