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

  • SEARCH
  • Home
  • 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 793975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:14:28+00:00 2026-05-14T22:14:28+00:00

OK, let’s say I am creating a program that will list users contacts in

  • 0

OK, let’s say I am creating a program that will list users contacts in a ListBox on the left side of the screen. When a user clicks on the contact, a bunch of messages or whatever appears in the main part of the window.

Now my question is: how should the MVVM triads look? I have two models: Contact, and Message. The Contact model contains a list of Message models.

Each ViewModel object will contain a single corresponding Model, right?

And what about the Views? I have a “MainView” that is the main window, that will have things like the menu, toolbar etc. Do I put the ListBox in the MainView? My confusion is with what to put where; for example, what should the ContactView contain? Just a single instance of a contact? So the DataTemplate, ControlTemplate, context menus, styles etc for that single contact, and then just have a ListBox of them in the MainView…?

Thanks.

  • 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-05-14T22:14:28+00:00Added an answer on May 14, 2026 at 10:14 pm

    The heart of MVVM pattern is the Model which is the structure of your data. So you have the Contact Model and the Message Model which are related and is well set. Now you want to design your interface. The UI contains a single window(the MainView). So you would need a single ViewModel. So what does the ViewModel consist of?

    Let us assume that you want to display only a single contact in your MainView and not a collection. Now your MainViewModel can just have references to your Contact’s properties which are to be exposed into the view.

    Contact c = /*Retrieve a contact from db*/;
    
    ContactName = c.Name;  //Create these two properties
    ContactPhone = c.Phone; //Assuming only these two properties are required by your view
    

    Now you can bind these properties to your MainView like this

    <Textbox Text={Binding ContactName} /> <!-- Assuming the DataContext is assigned -->
    <Textbox Text={Binding ContactPhone} />
    

    But we have to display a collection in our MainView. Hence we define the individual listitem as a new view. We also need a list of ContactName and ContactPhone. Hence we wrap these two properties into a class and make a list of it. This Class is termed as ViewModel.

    (Here you have to add Messages Property also)

    Hence the individual views have their own viewmodel. Now we integrate these views into our MainView.

    Now what should the MainViewModel contain?

    • List of ContactViewModels – ContactList
    • Selected ContactViewModel – SelectedContact
    • List of MessageViewModels – SelectedContactMessageList

    How are these wired up?

    • ContactList – bound to Contact ListView
    • SelectedContactMessageList – bound to Message ListView
    • SelectedContact – bound to Contact ListView’s SelectedItem. The setter should modify the SelectedContactMessageList according to the Selection like this
    SelectedContactMessageList.Clear();
    foreach (Message message in SelectedContact.Messages)
    {
        SelectedContactMessageList.Add(new MessageViewModel(message))
    }// converting the resulting models from SelectedContact.Messages to viewmodels
    

    That’s it. This is how I’ve understood MVVM.

    And about the point,

    Each ViewModel object will contain a single corresponding Model, right?

    No! Instead each View is mapped to a single ViewModel

    Create a ViewModel for each View in your application and have only those properties that are required by your View, in your ViewModel.

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

Sidebar

Related Questions

Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have thousands of users and I want to make the passwords
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's assume that we are building a high traffic site that will be used
Let's say I have an facebook application running using the JS SDK. First user
Let's say after I had login I will be prompt to enter the Name
Let's say I have multiple requirements for a password. The first is that the
Let's assume that a user votes for some movies in a scale of 1

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.