Can CanExecute not be a function of a parameter or is it a bad practice?

For example, the ability to execute a command depends on several VM properties. How in this case is more correct to do?

Option 1

 bool CanExecute() { return Prop1 && Prop2 == 1 && Prop3 is SomeType; } 

Option 2

Pass in the xaml markup to the parameter all the necessary properties through MultiBinding , wrap them in a converter that simply returns object[] as an object and in CanExecute use it?

In general, I myself do not see anything wrong with the first version, the only thing that confuses me is the attachment of the command functions to the specific context in which they are located.

  • one
    CanExecute can do without a parameter. - Bulson
  • @Bulson, I understand that. It can simply return true. But my question is not about it, but about the fact that if you need some properties of a VM for the result, do you need to pass them as a parameter or can you simply refer to them inside CanExecute ? More precisely, I understand that this is technically possible, but how correct is it? After all, not everything is right that is technically possible - iRumba
  • @Bulson, in short, to summarize all this information, the question will be: "Should the command be independent of the VM or not necessary?" - iRumba
  • A command can be considered a wrapper around a method. That method which should be executed on an event from a view. This method is in the view model, its "executability" or the ability to run for execution may depend on the availability of the necessary data in the view model, and on the data transmitted from the view through the command parameter. - Bulson
  • If to determine whether a command can be executed, all the source data is in the values ​​of the view model properties, then in CanExecute you do not need the parameter at all; and so you can determine by the values ​​of the properties in the view model you can execute the command or not. - Bulson

0