开发者

Multiple views in project

I want to create a project that contains 2 views and 2 viewmodels. One of the views will display persons that i get from a feed and the other will display the weather which I also receive from a feed.

Now in my viewmodellocator constructor I have static ViewModelLocator() { Container = new UnityContainer();

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

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

    // Access

    public Mai开发者_StackOverflow社区nViewModel Main
    {
        get
        {
            return Container.Resolve<MainViewModel>();
        }
    }     

then I set to use it in the view

But how can I add my weather view? In main my constructor looks like this public MainViewModel(ICommentService commentsService)

do I need an additional parameter in the constructor?

would appreciate if anyone could help


Personally, I don't register my Views with my container - only my ViewModels. I typically only have a single instance of any view, so I just create a new instance inside of it's parent ViewModel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜