I'm trying to get the essence of my last question and bring some more clarity to the description.
Given is an WPF form to submit new data with two textfields and a "Save" button. Both textfields are required fields and are bound to ViewModel properties. Button is bound to "Execute" relay command with Execute and CanExecute methods. CanExecute returns !HasErrors of the ViewModel. ViewModel implements INotifyPropertyChanged and INotifyDataErrorInfo interfaces. Property setter runs the validation for this property only.
The goals are:
- Disable the "Save" button initially.
- Enable the "Save" button only if both textfields are validated successfully without validation of the whole ViewModel on every property change.
For the first goal I use the isValidated bool property which is initially false and become true as soon as first validation occurred. This property is then checked together with HasErros in the CanExecute method. Is there a more elegant way?
I have no idea how to implement the second goal. Any thought on this?
THX
ICommandare you using? Do you have aRaiseCanExecuteChanged()method or similar? Call that every time the relevant properties change. - Gusdor