I am adopting MVVM pattern in WPF and have learned the use of Command
. But in my implementation, the delegate I assigned to implement CanExecute
is alw
When you set up your command, there's no reliable way for the runtime to know what data your CanExecute
will rely on in order to make its decision. So, when you have commands that are bound into your UI and are registered in the CommandManager
, the behaviour is that the CanExecute
for all commands is re-evaluated whenever the state of your application changes. The way WPF knows about this is when a bound property is updated, or when a UI event occurs.
Typically you'll see CanExecute
called whenever bindings update or when certain control events occur (for example, when a textbox's text is highlighted, the CanExecute
of the inbuilt Cut
and Copy
commands will change, and so the highlight event triggers a re-evaluation that I would imagine is bound to the MouseUp
event).