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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:50:29+00:00 2026-06-05T22:50:29+00:00

I have a View / ViewModel where a ProductList is loaded. This list is

  • 0

I have a View / ViewModel where a ProductList is loaded. This list is not visible on the screen.

What I need to do is show a new View/ViewModel (e.g. SelectProductView / SelectProductViewModel), pass the ProductList to them, and after a user selects a particular Product, close this view, and make use of selected product.

What is the best way to achieve this?

I am using MVVMLight, but I guess the ideas should not be restricted just to it.
The easiest way is to create a view, and pass collection to it, but that doesn’t sound MVVM friendly. I was thinking of creating a SelectProductViewModel from the first ViewModel and pass the collection to it, but I don’t know how would I automatically create SelectProductView and bind it to created SelectProductViewModel.

Edit: in my application view structure is a bit complex. I have a main view, which basically needs to host a SelectProductView, since this view must cover whole screen. MainView contains lots of child and grandchild views (through tabs), so there could be 3 different child views or grand childViews that could issue a request for a product to be selected. Also, some view will not have products preloaded, so this task should probably be propagated to a SelectProductViewModel.

Example of Structure:

                              MainView
                        /                   \
         ChildViewA                                   ChildViewB
            /  \                                       /     \
GrandChildViewA1 GrandChildViewA2            GrandChildViewB1 GrandChildViewB2

So, GrandChildViewA1, ChildViewB and GrandChildViewB2 could issue a request for a product to be selected. Only the view that issued a request should get the selected product, others should not bother with it. GrandChildViewA1 will have loaded products in it, but GrandChildViewB2 will not have ProductList loaded in it. This means, for performance sake, that GrandChildViewA1 should pass product list to SelectProductViewModel, while GrandCHildViewB2 will not have Product list in it, so SelectProductViewModel should fetch data from database.

  • 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-05T22:50:31+00:00Added an answer on June 5, 2026 at 10:50 pm

    I would create a generic viewModel which defines a contract for receiving data.

    public abstract class PassDataViewModel<T> : ObservableObject
    {
        public T Data { get; }
    }
    

    I would then create a more general ViewModel for your product list like so:

    public class SelectProductViewModel : PassDataViewModel<Product>
    {
        private Product _selectedProduct;
        private ObservableCollection<Product> _products = new ObservableCollection<Product>();
    
        public SelectProductViewModel(IList<Product> products)
        {
            _selectedProduct = _products.First();
        }
    
        public IEnumerable<Product> Products
        {
            get { return _products; }
        }
    
        public Product SelectedProduct
        {
            get { return _selectedProduct; }
            set
            {
                _selectedProduct = value;
                OnPropertyChanged("SelectedProduct");
                OnPropertyChanged("Data");
            }
        }
    
        public Product Data
        {
            get { return _selectedProduct; }
        }
    }
    

    You would use this in the following way:

    1. Your first viewModel can create an instance of the SelectProductViewModel (when a command is invoked, for example)
    2. You pass your products list to the new SelectProductViewModel instance.
    3. Use a DataTemplate to change the view on your screen (this post will show you how to do this).
    4. Have a property in the parent viewModel that returns the product returned from the data property of the SelectProductViewModel (you will need to propagate the PropertyChanged event to your parent viewModel).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mvvm(model view viewmodel) silverlight application that has several views that need
I have View(XAML included) attached to my ViewModel with commands. I need to invoke
I have a View with ViewModel as datacontext ( set in code) . In
I have a View that is hooked to a ViewModel. I have a singleton
In my WPF application I have a View that is given a ViewModel, and
I have a DatePicker working on a View which also has a ViewModel associated
I have senario in which one view and view has binding with multiple ViewModel.
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
Do you think it is alright from architectural stand-point to have ViewModel - View
I have View Model with inner ViewModel Address propery. public class CommonViewModel{ public AddressViewModel

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.