需要帮助设置MVVM Light ViewModelLocator [英] Need help setting up MVVM Light ViewModelLocator

查看:232
本文介绍了需要帮助设置MVVM Light ViewModelLocator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我需要一些帮助来设置ViewModelLocator.这是一个使用Galasoft MVVM Light Toolkit的Windows Phone 7应用.

As the title says, I need some help setting up my ViewModelLocator. It's a Windows Phone 7 app that uses the Galasoft MVVM Light Toolkit.

我的应用程序中有第二个页面,我需要连接到视图模型,但是在过去一个小时内在互联网上苦苦寻找之后,还没有真正找到将ViewModels添加到视图模型的简单示例.定位器.我需要的只是一个代码示例,该示例说明了我需要添加到定位器中的内容以及添加它的下落.

I have a second page in my app which I need to wire up to the view model, but after looking strenuously on the internet for the past hour, haven't really been able to find a simple example of adding ViewModels to the locator. All I need is a code example of what I need to add to the locator and whereabouts to add it.

感谢任何可以帮助我的人.

Thanks to anyone who can help me with this.

推荐答案

这是我的ViewModelLocator:

This is my ViewModelLocator:

public class ViewModelLocator
{
    public MainPageViewModel MainPage
    {
        get { return new MainPageViewModel(); }
    }
}

这是我的App.xaml的一部分:

This is a piece of my App.xaml:

<Application.Resources>
    <vm:ViewModelLocator
        x:Key="ViewModelLocator" />
</Application.Resources>

这是我的页面xaml的一部分:

This is a piece of my page xaml:

DataContext="{Binding MainPage, Source={StaticResource ViewModelLocator}}"

这篇关于需要帮助设置MVVM Light ViewModelLocator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆