从 MainViewModel 调用或发送值到其他 ViewModel mvvm mvvm light

发布于 2024-09-13 15:34:18 字数 1088 浏览 2 评论 0原文

我们正在使用 mvvm light 框架来构建我们的应用程序。在我们的 ViewModel 文件夹中,根据应用程序的不同功能,我们有许多 Viewmodel,如 orderSupplyViewModel、HouseholdSupplyViewModel 等文件。我们通过将 MainViewModel 设置为分部类,将所有这些 viewModel 包含在 MainViewModel 中。所以你可以说我们有一个 MainViewModel。现在我们已经完成了应用程序的 40%,我们需要将视图模型分离为一个分部类。这样我们就可以从主视图模型中调用不同的视图模型。该怎么办呢?以下是与名为 - 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()
        {


        }

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()
        {


        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小沫ゞ 2024-09-20 15:34:24

您不应该有一堆 MainViewModel 部分定义。您应该为每种类型的 ViewModel 创建单独 ViewModel 类。

在 Visual Studio、解决方案资源管理器、<您的项目> 中,右键单击 [ViewModel] 文件夹 ->添加->新项目... -> Mvvm Light ViewModel。这应该添加一个继承 ViewModelBase 的新 ViewModel 类。

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.

故人爱我别走 2024-09-20 15:34:22

为了以解耦的方式进行通信,MVVM Light工具包提供了messenger类。
它还可以启动对话框并提供回调。非常方便非常轻非常有用。

Messenger 的描述如下:http://www.galasoft.ch/mvvm/getstarted/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文