1

I'm currently working on my first MVVM project and I need some feedback on the ViewModels... well, I should actually miss out the plural 's': I have one big fat large MainViewModel right now.

I'm building a survey-analyzis-tool: There is a list of surveys from which users can pick one and a result page where infos for the selected survey are displayed. There is, e.g., the property "SelectedSurvey" which binds the user's selected survey. This property is needed for the result page as well.

Is one large ViewModel maybe not so bad after all?

peter
  • 2,103
  • 7
  • 25
  • 51
  • I think what you might be looking for is *Services*, for instance what MEF provides. *Dependency Injection* might be interesting as well. It's used to divide logic between different classes. Your question in its current form is very opinion based however.. There are a lot of different ways to exchange data between classes. Have you tried anything and what was the result? – default Mar 24 '15 at 08:33
  • So there is just a SurveyModel and a SurveyViewModel? how many models do you have? usually for each Model you create a ViewModel, If you have ViewModels that need to communicate you do it either though a ParentViewModel that references the ViewModels that need to communicate or if you want to decoupling you can do it through an a simple EventAggregator in which ViewModels subscribe to Events from other ViewModels, your app seems to be simple its better not to complicate things, and its common to use the same ViewModel instance in multiple Views. – Xi Sigma Mar 24 '15 at 08:44
  • 2
    @Sheridan: Imho, these questions are not asking the same. Or at least I would answer differently in this case – Liero Mar 24 '15 at 08:53
  • My question was more whether or not it would pay off to separate my MainViewModel. So far, my impression is that splitting up to several ViewModels would add a lot of overhead (Services, Messenger). – peter Mar 24 '15 at 09:03
  • The question was linked to answer the clearly stated question '*If I had two separate ViewModels "SelectionViewModel" and "ResultViewModel", how could I exchange this information?*'. However, if you don't actually want that question answered, I can reopen this question. – Sheridan Mar 24 '15 at 09:05

1 Answers1

2

You can use something like the MVVM Light Messenger to exchange data between ViewModels:

MVVM Light Messenger - Sending and Registering Objects

Generally speaking I try to stick to a 1:1 ratio of Views to ViewModels. If your View requires a truly huge ViewModel then perhaps you could eliminate some clutter by refactoring supporting methods into their own classes.

Community
  • 1
  • 1
goobering
  • 1,547
  • 2
  • 10
  • 24