Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:32:27+00:00 2026-06-17T09:32:27+00:00

I have a WPF application which follows the MVVM pattern. The application defines two

  • 0

I have a WPF application which follows the MVVM pattern. The application defines two views and view models so far:

  • LoginView(Model)
  • ProjectsView(Model)

Both view models need to access several properties from other view models.

Example:
LoginViewModel has a property ProjectList. ProjectsViewModel needs to access this property as well.

This is only a simple example. Later there will be several UserControls which all need to interact with each other.

Would it be a better idea to create one huge view model which all UserControls (views) set as their DataContext? If not, how can all the different view models interact with each other?

Remark:
This question is closely related to this one but with a different approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:32:27+00:00Added an answer on June 17, 2026 at 9:32 am

    You should definitely not make a huge “main view model” — this is an anti-pattern not dissimilar to a god object.

    The key idea here is that your viewmodels do not need to access several properties from other view models; rather, all of the viewmodels need to access specific pieces of information.

    Right now you are most likely injecting this information into each viewmodel at the time of instantiation. Instead of doing this, provide each viewmodel with a reference to a service — an application module that exposes this information through properties and/or methods. The information can be exposed in the form of scalar values if it’s extremely simple in nature, or in the form of models if it’s anything more complicated than that.

    Schematically this would look like

    /--------------\
    |  ViewModelA  |
    |              | <=======\
    |              |         |
    \--------------/         |  <--- information is pulled      /================\
                             +=========[model]===[model]======  |    Service     |
    /--------------\         |                                  \================/
    |  ViewModelB  |         |
    |              | <=======/
    |              |
    \--------------/
    

    The service should be injected into the viewmodels upon construction (either manually or by the DI container if you are using one). Each viewmodel should only require a reference to the service and enough information to tell to the service which model it’s interested in; it will then request that model from the service and populate its “interesting” properties based on that.

    This way of doing things is more involved than simply constructing a viewmodel object and setting its properties externally, but it will allow your application to grow in complexity without becoming unmanageable.

    For example, if there are lots of views that bind on different viewmodels and these viewmodels depend in complex ways on a number of models, a sane manner to work would be:

    1. A view/viewmodel pair is constructed
    2. The viewmodel requests any models it needs to know about from the service; it subscribes to an event that the service exposes to let subscribers know that a model has changed
    3. Changes are performed to the models through databound controls
    4. The view invokes a “save” command on the viewmodel
    5. In response to that, the viewmodel invokes a “save this model” method on the service
    6. The service persists the information and publishes a “model changed” event (see step 2)
    7. Other viewmodels interested in the same model know that the model has changed and can query the service for its new state

    This is possible if everything is routed through the service. Imagine what it would take to keep everything synchronized otherwise — the only way to cope would be to put all the information into a giant viewmodel and reference that from everything else. Ugly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPf Toolkit-datagrid..in my application which follows MVVM pattern. How I can
I have a WPF application that mostly follows MVVM, which I am trying to
Let's say I have a WPF application which makes use of the MVVM pattern.
I have a WPF application which is built on the MVVM design pattern. I
I have a WPF application which so far has been client only, but now
I have large WPF-MVVM application in which I have 1 subscribe and 2 publish
I have a WPF application which connects to a remote database over internet and
I have an XBAP WPF application which displays various pages inside of a Frame.
I have a C# WPF application which uses Excel interop libraries to generate and
I have created a wpf application into which I have added a user control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.