需要帮助设置 MVVM Light ViewModelLocator

发布于 2024-12-14 19:31:09 字数 248 浏览 5 评论 0原文

正如标题所示,我需要一些帮助来设置我的 ViewModelLocator。它是一个使用 Galasoft MVVM Light Toolkit 的 Windows Phone 7 应用程序。

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

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

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.

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.

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

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

发布评论

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

评论(1

丢了幸福的猪 2024-12-21 19:31:09

这是我的 ViewModelLocator:

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

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

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

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

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

This is my ViewModelLocator:

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

This is a piece of my App.xaml:

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

This is a piece of my page xaml:

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