【问题标题】:Multiple views in project项目中的多个视图
【发布时间】:2010-06-24 18:03:00
【问题描述】:

我想创建一个包含 2 个视图和 2 个视图模型的项目。 其中一个视图将显示我从提要中获得的人,另一个将显示我也从提要中收到的天气。

现在在我的 viewmodellocator 构造函数中 静态 ViewModelLocator() { 容器 = 新 UnityContainer();

        if (ViewModelBase.IsInDesignModeStatic)
        {
            Container.RegisterType<IPersonService, Design.DesignDataService>();
        }
        else
        {
            Container.RegisterType<IPersonService, PersonService>();
        }

        Container.RegisterType<MainViewModel>(new ContainerControlledLifetimeManager());
    }

    // Access

    public MainViewModel Main
    {
        get
        {
            return Container.Resolve<MainViewModel>();
        }
    }     

然后我设置在视图中使用它

但是如何添加我的天气视图?在主要我的构造函数看起来像这样 公共 MainViewModel(ICommentService cmetsService)

我需要在构造函数中添加一个额外的参数吗?

如果有人可以提供帮助将不胜感激

【问题讨论】:

    标签: .net mvvm-light


    【解决方案1】:

    就我个人而言,我不会在我的容器中注册我的视图 - 只是我的视图模型。我通常只有一个视图的单个实例,所以我只是在它的父 ViewModel 中创建一个新实例。

    【讨论】:

    • 是的,但我有很多相同视图的实例(只有不同​​的 url)
    • 因此您可以根据需要发送带有 url 的 notificationMessage。
    猜你喜欢
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多