Question

The question is simple. In MVVM, is it the responsibility of the ICommand implementation to perform CanExecute and Execute logic, or to invoke logic that resides under control of the ViewModel?

I am asking because when I try to implement logic in the ICommand implementation, it feels like a lot of tight coupling is going on between the Command and the ViewModel, and other objects. But when I try only to invoke methods from the ICommand implementation, I get the sense that I have a lot of excessive code for what amounts to a method call. I think this problem would clear itself up if I was more clear on the single responsibility of the ICommand implementation.

Logic or Invoke?

Was it helpful?

Solution

Invoke.

It's a placeholder in your ViewModel that is being called from your View. It should then direct you to the correct method (execute) under the correct circumstances (can execute).

MVVM is more verbose than other approaches, and it might be a bit annoying to write the boiler code, but the return you get is quite big.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top