I’m new to MVVM and WPF itself. I need to do some prototyping in WPF and reached conceptual question.
Suppose you have server which sends you data. Regardless of whether you displaying that currently or not you need to store it in cache, this is your “real data” and at some time you will need to put it on UI (when user opens particular screen), this is your viewmodel.
My question is quite obvious – should I bind UI to a real data stored in some service or should I do a viewmodel wrapper around that data and bind to it?
In the first case I receive “The calling thread cannot access this object” exceptions unless I use Dispatcher, but calling Dispatcher in model doesn’t look right
In the later case I will need to:
- copy 90% of the data from “real model” to wrapper
- manually watch changes in underlying “real data” to update viewmodel which in case implements INotifyPropertyChanged.
What is the correct way?
The way it is most appropriate, is to have your ViewModel pretty similar to your View’s needs. It means if your View has a list, then you most likely will need at lease 2 properties on your ViewModel, one for the ItemSource and the other for the selected Items.
Regarding the real data stored, I would say, put it being accessed by your service. Maybe you use the WPF or Silverlight, so you will be protecting your true physical data. And may exchange, just the proper information the view requires.
I hope it helps. If you would like to share some arquitectural aspects of your project, we might give you more advices.