I use ICommand
in the ViewModel to be able to add/remove items from collections etc.
I also have validation that belongs in the model classes to validate textboxes etc.
Is there a way I can use the two (ICommand
in the ViewModel + the Validation in the model) to disable the button if a textbox has failed Validation? I ask because the ICommand
exposes the CanExecute
event so I guess it would be wise to use that!
You got the idea right. Implement a CanExecute
method that returns the result of your model validation so that when it fails, the button will be disabled.
Then, you must make sure that the CanExecute
is called again when the validation conditions change - for instance, when a binding property has changed. In order to do so, you may require more advanced implementations of ICommand
such as Prism's DelegateCommand
.