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 1078151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:40:52+00:00 2026-05-16T21:40:52+00:00

I have 2 ViewModels. One is called User (containing basic information, nothing fancy) and

  • 0

I have 2 ViewModels. One is called User (containing basic information, nothing fancy) and another called Group, which has as a property, an IEnumerable of User. This IEnumerable is backed by a dictionary (there are a lot of users, need to search them fast)

public class Group
{
    #region Fields
    private Dictionary<string, User> userLookup;
    #endregion //Fields
    public Group()
    {
        userLookup = new Dictionary<string, User>();
    }


    public User[] Users
    {
        get
        {
            return userLookup.Values.ToArray<User>();
        }
        set
        {
            foreach (var user in value)
            {
                if (!userLookup.ContainsKey(user.Login))
                    userLookup.Add(user.Login, user);
            }
        }
    }

    public bool AddUser(User user)
    {
        if (userLookup.ContainsKey(user.Login))
            return false;
        userLookup.Add(user.Login, user);
        return true;
    }
}

Now, The GroupViewModel class needs to add a new user, but all the GroupViewModel gets shown is UserViewModels, and the Add functionality only accepts type User. Currently i have an Internal function on the UserViewModel which exposes the underlying User object, i was just wondering if that defeated the purpose of using MVVM.

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-16T21:40:53+00:00Added an answer on May 16, 2026 at 9:40 pm

    It was my understanding that in MVVM the purpose of the ViewModel was to provide the public data and interfacing for the view. So if the view requires the exposition of this data then no, I don’t think this breaches MVVM, i think its quite inline with the framework. Though some of the more experienced developers might have more insight.

    Also in your Users property, you double up on your AddUser code in the setter.

    set
    {
        foreach (var user in value)
            AddUser(user);
    }
    

    Might be easier and save you having to change the setter if the conditions for entering a user change or become more complicated.

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

Sidebar

Related Questions

I have an MVVM application. In one of the ViewModels is the 'FindFilesCommand' which
I have senario in which one view and view has binding with multiple ViewModel.
I have the following ViewModel, which is the base class of other ViewModels that
I have a c# control library which contains my models, viewmodels and views. I
ViewModel I have a property of type Member called KeyMember . The 'Member' type
I have a ViewModel called EntityRating, one of whose properties is AverageRating. When I
In my SilverLight application, I have a property in my ViewModel called 'vmProperty' and
I have a ViewModel called MainWindowViewModel. In this I have a property that shows
I have a controller called EmailController , which is (you guessed it) responsible for
I have a WPF app that uses a business object called Visit, it has

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.