문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top