I just implemented a call of Execute for a Command without calling CanExecute first.
From debugging I would tell that CanExecute is called though; however, I'm not sure if this is coincidence.
I'd like to know if I can rely on the fact that CanExecute is implicitly called whenever I raise the Execute by hand, or if I should ensure calling CanExecute myself?
You can't rely on that.
CanExecute()
is called when aCommand
is bound to a Command-enabled UI item like a Button (via theCommandManager
) but checkingCanExecute()
inExecute()
itself would be an implementation detail for a specific implementation ofICommand
and is not implied.However, it's an interesting idea and not a bad one considering how often I've had to do the following in my own code: