Viewmodel validation on Initialize

Topics: Questions
Nov 18, 2014 at 1:14 PM
Viewmodel is always validated on Initilize?

No mather if

ValidateModelsOnInitialization = false;
SuspendValidationForAllModels = true;

Is it not possible to disable the validation in viewmodel on initialize?
Coordinator
Nov 19, 2014 at 10:19 AM
ValidateModels != the validation of the view model itself. It means that if you assign a value to a property with a Model attribute, they won't be validated when the model is initialized.

Disable the validation of the vm in the ctor. I think there is even a property something like SuspendValidationUntilFirstSave or something like that.
Nov 19, 2014 at 10:32 AM
SuspendValidationUntilFirstSave.

I don't use/need the Save Method. I do not save anything. On my view I have a lot of comboboxes in nested viewmodel. Everthing i have to validate is that some combinations of the selected values are not valid. If the combinations are valid I can send the configuration to our machine.
Coordinator
Nov 19, 2014 at 10:41 AM
It doesn't matter if you actually save something. It means that it is suspended until the first call to Save (which Catel will do you for automatically).
Nov 20, 2014 at 9:05 AM
?? Catel calls automaticaly save? Also if I dont save anything at anytime?
Coordinator
Nov 20, 2014 at 10:16 AM
It calls save, it doesn't actually save anything. Please read the docs, it's in there.
Nov 21, 2014 at 6:31 AM
Coordinator
Nov 21, 2014 at 10:35 AM
See https://catelproject.atlassian.net/wiki/display/CTL/Introduction+to+the+nested+user+controls+problem

"Saving a chain of nested view models works exactly the same as the validation. First, the view model saves all children, then itself and finally reports back its result to the parent."

Catel always calls either Save or Cancel on the view model when the view is unloaded (or when the parent vm saves / cancels (coming from a data window for example). It doesn't actually save something, it calles IViewModel.SaveViewModel or IViewModel.CancelViewModel. After one of these 2, it calls IViewModel.CloseViewModel.
Nov 21, 2014 at 12:17 PM
Ok but only when the viewmodel is unloaded, closed, canceld ore something else.

But I do not close the viewmodel its open. I need validation at runtime but not on loading. Only if any property is changed.