开发者

Calling or sending values from MainViewModel to other ViewModels mvvm mvvm light

开发者 https://www.devze.com 2023-01-11 10:34 出处:网络
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 funct

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 cla开发者_开发知识库ss.
        /// </summary>
        public void OrderSuppliesViewModel()
        {


        }


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消