MVVM Binding Orthogonal Aspects in Views e.g. Application Settings

Posted by chibacity on Stack Overflow See other posts from Stack Overflow or by chibacity
Published on 2010-05-12T15:26:07Z Indexed on 2010/05/12 22:34 UTC
Read the original article Hit count: 290

Filed under:
|

I have an application which I am developing using WPF\Prism\MVVM. All is going well and I have some pleasing MVVM implementations. However, in some of my views I would like to be able to bind application settings e.g. when a user reloads an application, the checkbox for auto-scrolling a grid should be checked in the state it was last time the user used the application.

My view needs to bind to something that holds the "auto-scroll" setting state. I could put this on the view-model, but applications settings are orthogonal to the purpose of the view-model. The "auto-scroll" setting is controlling an aspect of the view. This setting is just an example. There will be quite a number of them and splattering my view-models with properties to represent application settings (so I can bind them) feels decidedly yucky.

One view-model per view seems to be de rigeuer...

What is best\usual practice here?

  • Splatter my view-models with application settings?
  • Have multiple view-models per view so settings can be represented in their own right?
  • Split views so that controls can bind to an ApplicationSettingsViewModel? = too many views?
  • Something else?

Edit 1

To add a little more context, I am developing a UI with a tabbed interface. Each tab will host a single widget and there a variety of widgets. Each widget is a Prism composition of individual views. Some views are common amongst widgets e.g. a file picker view. Whilst each widget is composed of several views, as a whole, conceptually a widget has a single set of user settings e.g. last file selected, auto-scroll enabled, etc. These need to be persisted and retrieved\applied when the application starts again, and the widget views are created.

My question is focused on the fact that conceptually a widget has a single set of user settings which is at right-angles to the fact that a widget consists of many views. Each view in the widget has it's own view-model (which works nicely and logically) but if I stick to a one view-model per view, I would have to splatter each view-model with user settings appropriate to it. This doesn't sound right ?!?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm