0
votes

We are using mvvm light framework to build our application. In our ViewModel folder, we have number of Viewmodel like orderSupplyViewModel,HouseholdSupplyViewModel etc files as per the different functionality of the application. We have included all these viewModels in the MainViewModel by making the MainViewModel as partial class. So you can say we have one MainViewModel. Now we have completed 40% of the application and we need to separate the view Models as one partial class. So that we can call the different viewmodels from the mainviewModel. How to go about it? Following is the code realted to one viewmodel named - OrderSuppliesViewModel

namespace ParentalHealthClient.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// </summary>
    public partial class MainViewModel : ViewModelBase
    {
        private List<UserMedicalSupplyBO> _selectedFavouriteMedicalItems;
        private List<HouseholdItemsBO> _selectedFavouriteHouseHoldItems;
        private List<OrderSuppliesBO> _selectedOrderItems;
        private HouseholdSuppliesDAO _dataAccessForOrder;

        /// <summary>
        /// Initializes a new instance of the OrderSuppliesViewModel class.
        /// </summary>
        public void OrderSuppliesViewModel()
        {


        }
2

2 Answers

0
votes

To communicate in a decoupled way MVVM Light toolkit provides the messenger Class. It can also launch dialogs and provide callbacks. Very handy very light very useful.

The Messenger is discribed here: http://www.galasoft.ch/mvvm/getstarted/

0
votes

You should NOT have a bunch of MainViewModel partial definitions. You should create individual ViewModel classes for each type of ViewModel.

In Visual Studio, Solution Explorer, <Your Project>, right-click on [ViewModel] folder -> Add -> New Item... -> Mvvm Light ViewModel. This should add a new ViewModel class which inherits ViewModelBase.