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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:37:09+00:00 2026-06-16T00:37:09+00:00

I’ve seen a few code examples that basically create a View-Model for the Master,

  • 0

I’ve seen a few code examples that basically create a View-Model for the Master, and a View-Model for the Details. Then they connect the Master to a View with a DataGrid, then the selected item of the Master View-Model is bound to a SelectedItem property of type ObservableObject(of DetailViewModel), which is then sent over to the Detail View-Model, which is then bound to a detail view… Such as is recommended here. Or something like this

After reading this… http://blogs.msdn.com/b/adonet/archive/2011/03/08/ef-feature-ctp5-code-first-model-with-master-detail-wpf-application.aspx

This.. One Model Entity, Multiple Pages -> Multiple Views? Multiple ViewModels?

And this… Multiple ViewModels associated with a single view

I’m very confused:) Seems like the preferred Prism way of doing this is to have a separate ViewModel for master and detail though, in my cause I feel it will be quite a bit more work to do it that way.

It seems to me that if your using Entity Framework DbContext and are utilizing the .Local property for binding it would make more sense to use one View-Model for Master/Detail situations.

  • 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-16T00:37:09+00:00Added an answer on June 16, 2026 at 12:37 am

    Binding to the DbContext or any of it’s properties directly would be a bad idea because it would expose the Model to the View which violates the idea behind MVVM. (The View knows the ViewModel, the ViewModel knows the Model).

    In a master-detail scenario you have two different viewmodels with 2 different views each because they each have different roles.

    • The Master’s role is to present a list of choices and a way to navigate to their details.
    • The Detail’s role on the other hand is to present a single element, possibly with a way to alter values.

    Imagine you have a list of Products as your data model, each product has an id, a name and a price:

    class Product {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Price { get; set; }
    }
    

    Also you have some sort of data model which contains a list of products:

    class ProductRepository {
        private List<Product> products = new List<Product>();
        public List<Product> Products 
        { 
            get { return this.prodcuts; }
        }
    }
    

    Then your MasterViewModel’s role is to exposes the Products list of the ProductRepository model and to provide a way to switch to the detail view:

    class ProductsViewModel {
        private ProductRepositry productsModel = new ProductRepository();
        private ObservableCollection<Product> products = new ObservableCollection<Product>(productsModel.Products);
    
        public ObservableCollection<Product> Products
        {
            get { return this.products; }
        }
    
        public ProductViewModel Detail { get... private set... } // setter includes PropertyChange
    
        public ICommand ViewDetail { get... }
    
        public void ViewDetail(Product detail)
        {
            this.Detail = new ProductViewModel(detail);
        }
    }
    

    The ProductViewModel‘s sole responsibility is to present a Product:

    class ProductViewModel {
        public string Name { get... set... } // Again a PropertyChange would be necessary for propert binding
        public int Price { get... set... } // dito
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.