I have a dialog with a few fields. Some of them use validation – ValidatesOnExceptions=True in my case.
I have a data object with INotifyPropertyChanged that I bind to dialogs’ DataContext.
I also have a “Save” button. Validation works fine, but only after I edit each field.
If dialog is opened and closed immediately, validation will not fire.
What should I do prevent Save from firing in this case (use case: open dialog, press save immediately)
Use command bindings for the save button, then you can enable/disable the button depending on your current state
see this simple tutorial and if you want further explantion the msdn article, also josh smith gets more in depth
We handle your above situation by using a combination of commands and an IsValid property on the underlying model we are binding to. We do validation at the business model level (some times in the ui as well) and when the business model is valid we enable the command, or as in your case, save button.
Here is a sample of the style we apply to our text boxes (we derive from text box and give it another property called SimpleField. This field has the properties IsValid, IsDirty, IsReadOnly, ErrorMessage and DatabaseValue. This enables us to know if the field is valid, whether it has changed if it is read only (i.e. the user doesnt have the permission to change the value or it is locked for another reason), if there is an error message (associated with the IsValid property) and also the database value (for when the field has changed, the user can see the original value) We use all of these properties in the style below