Skip to content

RelayCommand: CanExecute no longer automatically checked on Execute #240

Answered by Sergio0694
RedX2501 asked this question in Q&A
Discussion options

You must be logged in to vote

We decided not to do this as it was technically against the ICommand interface (see here). The docs for Execute say that that method will execute the command action, they don't mention anything about it doing the "can execute" checks again. It's whoever's using the command that's responsible for calling CanExecute first, or it's the UI framework binding to the command that's responsible for subscribing to CanExecuteChanged and then calling CanExecute to update the IsEnabled state for whatever button or control is bound to the command. This is also what the command implementation from WPF is doing. What was in MvvmLight was not really following the ICommand contract, so we rectified that i…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@RoarkDude
Comment options

Answer selected by Sergio0694
Comment options

You must be logged in to vote
1 reply
@Arlodotexe
Comment options

Comment options

You must be logged in to vote
5 replies
@StephanZilke
Comment options

@RedX2501
Comment options

@Sergio0694
Comment options

@RedX2501
Comment options

@Sergio0694
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants