質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top