I have following WPF-MVVM setup:
- A view with 2 textfields bound to the properties of the ViewModel with UpdateSourceTrigger=PropertyChanged and a button with a command binding to a relay command (CanExecute, Execute methods)
- ViewModel which implements INotifyDataErrorInfo with 2 properties annotated with [System.ComponentModel.DataAnnotations.Required]. Property setter call private ViladateProperty method, which stores the validation results in the errors dictionary. HasErrors property getter checks the errors dictionary to return the appropriate value.
The aim is to enable the button as soon as the whole form validates correctly. My two questions on this are:
- How to implement the CanExecute method of the button relay command without calling the validation on the whole model for every property change?
- What is the best way to "delay" the UpdateSourceTrigger to set the according property not on every keystroke but, for example, after one second of "no input"?