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

The Archive Base Latest Questions

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

One thing I struggle with on MVVM pattern is when I try to implement

  • 0

One thing I struggle with on MVVM pattern is when I try to implement additional Windows. When I create an additional Window and ViewModel to go along with that Window that is going to serve a particular purpose my design seems to get lost.

Take for example I have a very simple application. It’s a list of people from which I can Add/Delete/Restore. My initial design I handle Delete/Restore from the ViewModel, but Adding I must request information from the user. Given this, I created a new Window and ViewModel (AddWindow/AddViewModel). At this point I get lost. I’ve read about creating Controllers to communicate between, but I’m not even sure that makes sense.

On the AddWindow a user can fill in two fields (first name/last name) and then click Add (or cancel) in which case at that point the data needs to be passed back to the ViewModel so it can be added to the collection so it’s updated (also the AddWindow must close).

How can I think about this in a better manner and what can I do here to resolve such a simple problem?

  • 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:53:26+00:00Added an answer on June 17, 2026 at 9:53 am

    Create a new class, ApplicationModel, to hold all the user data. Your “Main” view model should create it and then hold it in a property. Your View need to bind to the full path to the data in the model:

    <DataGrid ItemsSource="{Binding Path=Model.ListOfThingsToDo, Mode=OneWay}" ... />
    

    In the constructor of your new ViewModels you supply that Model as a parameter. That way all your ViewModels will share the same Model and the new ViewModels can modify/view the same data as your “main” ViewModel.

    /// <summary>
    /// ViewModel for the Main Window
    /// </summary>
    class MainViewModel
    {
        public ApplicationModel Model { get; set; }
    
        public MainViewModel()
        {
            Model = new ApplicationModel();
            Model.ListOfThingsToDo.Add("Clean the yard");
            Model.ListOfThingsToDo.Add("Walk dog");
        }
    
        // Some method that will be called when you want to open another window
        public void OpenTheWindow()
        {
            var modalViewModel = new NewTaskViewModel(Model);
            // Create an instance of your new Window and show it. 
            var win = new NewTaskWindow(modalViewModel);
            win.ShowDialog();
        }
    }
    
    /// <summary>
    /// Model to hold the data
    /// </summary>
    class ApplicationModel
    {
        public ObservableCollection<string> ListOfThingsToDo { get; set; }
        public ApplicationModel()
        {
            ListOfThingsToDo = new ObservableCollection<string>();
        }
    }
    
    
    /// <summary>
    /// ViewModel to handle adding new things to do
    /// </summary>
    class NewTaskViewModel
    {
        public ApplicationModel Model { get; set; }
    
        public NewTaskViewModel(ApplicationModel model)
        {
            Model = model;
        }
    
        // Add methods here that will be called to add tasks to the Model.ListOfThingsToDo
        public void AddTask()
        {
            Model.ListOfThingsToDo.Add("the new task to do");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing that bothers me about nHibernate is that it is not 100% compile
One thing that really bothers me about Google Code is that fact that it
One thing that's bothered me with vi is that paste (p) inserts lines after
One thing that seems particularly easy to do in the Flash IDE but difficult
Whilst building a Windows Phone 7 app. using the MVVM pattern we've struggled to
My (rather small) company develops a popular Windows application, but one thing we've always
One bad thing about using the autoloader is, that it doesn't know where to
One thing I see in some DDD enterprise apps that I work on, is
One thing that always bugged me, is that I do not see the base
I am currently developing .NET code and am using VS2010. One thing I struggle

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.