I am writing a small application for learning WPF / MVVM, and I have my own puzzle problem, I have a viewmodel object that is ready to work, but I do not know where to place it.
The view model is a single Windows data (some values โโof the sliders, the progressbar value and several text lines. Some of them are directly tied to the model that is being exposed, others are in view mode so as not to add new functions to the model.)
I will need only one of these objects at a time (per window, but I only allow 1 window), although it really is not a singleton. It will exist for the window's lifetime, though (is this normal?)
So my question is: should I viewmodel instance as a static resource in App.Xaml, as a member of the App.xaml.cs class in the code behind (inside the overridden OnStartup method), or as a resource in Window.xaml or as an object in Window.xaml. cs.
I saw how people used it as a local resource and as a global object in the startup process, but it seems to me that it should not be in the code (all I do is throw it into the air as soon as it finally can take care of everything else. That's the whole point, actually).
So, thoughts on where the view model should be displayed?
Snark source
share