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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:51:19+00:00 2026-06-09T09:51:19+00:00

I am refactoring my application to utilize MVVM. I used to keep a List<Product>

  • 0

I am refactoring my application to utilize MVVM. I used to keep a List<Product> variable in the Application class that I was able to bind a ListView to. This List made up my Data layer. The Page with this ListView is a master/detail layout. With MVVM, I am thinking that the List should now hold instances of the ProductModel as it is the data layer. If I should be binding to ViewModels, do I need a separate List of ViewModels too?

  • 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-09T09:51:21+00:00Added an answer on June 9, 2026 at 9:51 am

    You might need to take a different perspective on MVVM. Your View is the page with the controls (XAML) and your ViewModel is the glue between your data model and the page. The View’s entire data context will be set to the ViewModel (done either in the XAML directly or in code-behind depending on which MVVM camp you subscribe to).

    In your example, you would move List<Product> onto the ViewModel as ObservableCollection<Product> and make sure that your ViewModel implements the INotifyPropertyChanged interface. INotifyPropertyChanged is the contract the View uses to know when to update it’s binding. You will use an ObservableCollection<T> instead of a list because ObservableCollection<T> implements INotifyPropertyChanged itself.

    Your View’s DataContext property will be set to an instance of the ViewModel. On the View, the ListBox control’s ItemsSource property will be set to bind to the Product collection. You can then have methods inside of your ViewModel that will be responsible for communicating with your data store to populate the observable collection.

    ViewModel

    public class MyViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private ObservableCollection<Product> _products = null;
        public ObservableCollection<Product> Products
        {
           get { return _products; }
           set
           {
               if( _products != value )
               {
                   _products = value;
    
                   if( this.PropertyChanged != null )
                   {
                       this.PropertyChanged( this, new PropertyChangedEventArgs( "Products" ) );
                    }
                }
            }
         }
    
         // have code in here that loads the Products list from your data store (i.e. service call to database)
    }
    

    View Code-Behind

    public MyView()
    {   
        InitializeComponent(); 
        this.DataContext = new MyViewModel();
    }
    

    View

    <ListBox
        ItemsSource={Binding Path=Products, Mode=OneWay}
        SelectedItem={Binding Path=SelectedProduct, Mode=TwoWay}
        ...
    />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently refactoring a Silex\Application that has grown bigger than initially expected. As
I've been tasked with porting/refactoring a Web Application Platform that we have from ASP.NET
I'm refactoring a .Net web application that is in <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML
I recently did some refactoring of my mvc application and realized that there are
I'm currentlly refactoring an application using a lot of this: StringBuffer buff1 = new
I'm refactoring a WinForms (.NET 4) application that makes use of a TabControl to
I am refactoring an existing VB.NET application to use Linq. I've been able to
While tuning the application, I found this routine that strips XML string of CDATA
I have a PHP application that has grown in size. The database used to
I am in progress of refactoring a C++ application of mine. Before I used

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.