I am working on a large MVVM application. I am using the MVVM light toolkit for this. The application is like a web browser with back and forward buttons. The main view is an user control. I laid the back and forward buttons in the main view user control. The main view in turn has user controls. The user controls change when the back and forward buttons are clicked. The main ViewModel keeps track of the current user control and loads the next one depending on the button click.

All these user controls are loaded depending on the selection(ID) made on the first step. Lets say, the main view is a search screen and we select a customer. The next screens would be Address, Billing, Requests, etc. These screens does not share any data. But the data is for the same customer.

So, is it a good practice, to store the customer ID in the main view? If I do this, I should have a UserControl_Loaded event bound to a command, where I would then request for Address and Billing Info.

Or I can move the buttons(back and forward buttons) to each user control instead of the main view, Pass the customer ID with the message which would load the next view.

Which is better?

  • You should better ask this kind of questions on stackoverflow imho. I will tell you so much: It's a good practice to have the customer in your main ViewModel, preferably as an object or aggregate and not just as an id. Make use of DataTemplates, have subordinate ViewModels and keep them clean (no concrete UI stuff in there!). The main ViewModel can instantiate subordinate ViewModels, passing them the customer via the constructor. The ActiveViewModel Property of the main ViewModel can be databound to the Content of your MainView (the one with the buttons). WPF templating will do the rest.
    – Falcon
    Commented Aug 12, 2011 at 21:28
  • Hi, I am new to stack overflow. wasn't sure how I got to this section too. So what is the difference between this one and the other?
    – katie77
    Commented Aug 12, 2011 at 22:58

1 Answer 1


In your main CustomerViewModel I would have

  • Customer object
  • ObservableCollection<ViewModelBase> CustomerSubViewModels
  • int CustomerSubViewModelIndex
  • BackCommand
  • ForwardCommand
  • ViewModelBase CurrentView which is returns CustomerSubViewModels[CustomerSubViewModelIndex]

Your main CustomerView would contain a ContentControl with it's Content bound to CurrentView, and Back/Forward buttons which would change the CustomerSubViewModelIndex +- 1, which in turn alters the page displayed in the CurrentView. DataTemplates would be used to define how they should be drawn inside the ContentControl.

Your pages like Addresses, Billing, Requests would all be stored in the CustomerSubViewModels Collection, and I would pass them the Customer properties they need from within the CustomerViewModel. That could be a value like CustomerId, a property like Customer.Addresses, or even the entire Customer object. I would use

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.