简体   繁体   English

在MVVMCross中匹配ViewModel和View

[英]Matching ViewModel and View in MVVMCross

I have an MVVM Cross application, and I'm trying to figure out why the initial screen isn't showing (this is on WinRT). 我有一个MVVM Cross应用程序,我试图弄清楚为什么未显示初始屏幕(这在WinRT上)。

The following code looks like it loads the ViewModel MainViewModel : 以下代码看起来像它加载了ViewModel MainViewModel

var setup = new Setup(rootFrame);
setup.Initialize();

var start = Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.ViewModels.IMvxAppStart>();
start.Start();

However, the Start method of MainViewModel never gets called. 但是,永远不会调用MainViewModelStart方法。 The reason appears to be this error in the output: 原因似乎是输出中的此错误:

Error seen during navigation request to MainViewModel - error KeyNotFoundException: Could not find view for MyApp.PCL.ViewModels.MainViewModel

So, here's my guess as to the problem: it's looking for MyApp.PCL.ViewModels.MainView , Obviously, this doesn't exist. 因此,这是我对问题的猜测:它正在寻找MyApp.PCL.ViewModels.MainView ,显然,这并不存在。 The view is in: MyApp.Views.MainView . 该视图位于: MyApp.Views.MainView Is my assumption correct and, if so, how can I persuade MVVMCross to look in the correct place? 我的假设正确吗?如果是,我该如何说服MVVMCross查找正确的位置?

EDIT: 编辑:

The Setup method is called from the MyApp.Windows WinRT app. MyApp.Windows WinRT应用程序调用Setup方法。

protected override IMvxApplication CreateApp()
{
    return new MyApp.PCL.App();
}

MyApp.PCL is a portable class library that is referenced from MyApp.Windows . MyApp.PCL是从MyApp.Windows引用的可移植类库。 MyApp.PCL contains the ViewModels, and MyApp.Windows contains the views. MyApp.PCL包含ViewModel,而MyApp.Windows包含视图。

I have tried to override Start() : 我试图覆盖Start()

public class MainViewModel 
    : MvxViewModel
{

    public override void Start()
    {            
        System.Diagnostics.Debugger.Break();
        base.Start();
    }

but this never gets hit. 但这永远不会受到打击。

Massive Doh! Do! here, but I'll post the solution; 在这里,但我将发布解决方案; my view was not using the MvxStoreView, but the standard StoreView. 我的视图不是使用MvxStoreView,而是使用标准的StoreView。

The solution was to change the view as follows: 解决方案是按以下方式更改视图:

 ...
 xmlns:views="using:Cirrious.MvvmCross.WindowsStore.Views"
 ...
<views:MvxStorePage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM