Scenario.
- ViewModel has a property
State
. - View has a ComboBox that allows to change value of
State
. - ViewModel needs to run some validation (call
bool ValidateState(State value)
method) before setting value ofState
property.
Question.
How would you implement it?
My concerns.
- I want my solution to be generic so I could use it in different similar scenarios. For example in scenario where
ValidateState()
is anasync
method. - I do not want change value of
State
in ViewModel unless I 100% sure it’s valid. - If new value of
State
is not accepted (is not valid) I want ComboBox to keep having the old value as selected.
Disclaimer. I know there are multiple ways of implementing it. Also I’m not a MVVM novice. I would like to discuss which solution you think better suits this scenario and possibly discuss pros and cons of it.