When executing a custom RoutedUICommand
manually from code-behind, like this:
MyCommands.MyCommand.Execute(parameter, target)
do I need to call the CanExecute
method first or is this already done inside the Execute
method?
When executing a custom RoutedUICommand
manually from code-behind, like this:
MyCommands.MyCommand.Execute(parameter, target)
do I need to call the CanExecute
method first or is this already done inside the Execute
method?
Do not assume that CanExecute will get called with Execute. The interface for ICommand does not imply that it calls CanExecute when Execute is called, so if it is important to you that it only execute when CanExecute is true, simply check it yourself.
Also, scanning the de-compiled code for RoutedUICommand, I don't see anywhere that checks CanExecute within Execute.
It is really more of the consumer's responsibility to determine when to call Execute/CanExecute.
You should call CanExecute manually if you need, Execute will not check it!
You shouldn't assume that CanExecute
is called by the Execute
method, since there is nothing to enforce that behavior. So IMO you should call CanExecute
yourself