Search code examples
c#mvvmwindows-runtimemvvmcross

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).

The following code looks like it loads the 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. 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. The view is in: MyApp.Views.MainView. Is my assumption correct and, if so, how can I persuade MVVMCross to look in the correct place?

EDIT:

The Setup method is called from the MyApp.Windows WinRT app.

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

MyApp.PCL is a portable class library that is referenced from MyApp.Windows. MyApp.PCL contains the ViewModels, and MyApp.Windows contains the views.

I have tried to override Start():

public class MainViewModel 
    : MvxViewModel
{

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

but this never gets hit.


Solution

  • Massive Doh! here, but I'll post the solution; my view was not using the MvxStoreView, but the standard StoreView.

    The solution was to change the view as follows:

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