✅ Correct MVVM approach for displaying models representing settings
Given that I have a set of models representing settings, When I supply then to a UI utilizing MVVM, And display each settings with a respective UI component, Then the user can change the given setting And the change will be reflected in the model.
As far as I've understood, Models shouldn't really be reactive, i.e., shouldn't implement the
INotifyPropertyChanged
INotifyPropertyChanged
interface. This goes inline with the motive to keep models very simple, containing primarily properties.
Assume that I have generic models representing, e.g., a Toggle, Text input, Number input, and a Date input settings. They share the same interface
ISettingsElement
ISettingsElement
, and are exposed to the View via the respective ViewModel. Displaying specific UI elements based on the provided model is pretty easy. But how do I make sure that the model values are two-way-bound to the UI elements?
E.g., I wish to display my collection of settings, and provide the user with a
Clear
Clear
or
Defaults
Defaults
button. The ViewModel would naturally expose respective
ICommand
ICommand
implementations to do exactly that. But... going through the Models and modifying their configured values won't be reflected in the UI.
Or, is there a non-hacky way to tell the parent UI control to refresh itself?
All this seems a bit hacky and limiting, when trying to do clean MVVM... Hopefully, you'll be able to provide me the missing puzzle piece for correctly understading MVVM and implementing the settings feature.