Cheesebaron provided a very good example of combining those worlds together.
Adrian Sudbury, the creator of the Ninja Coder VS Extension, is planning to release a Xam.Forms + MvvmCross option in the extension soon.
I missed one important thing in Cheesebaron's solution. You have no possibility to inject dependencies into the ContentPages (you might argue if this makes sense).
One use case here would be the MvvmCross Messenger PlugIn. An example could be if you want to send a message to your View to display an alert dialog when the login fails etc.
Cheesebaron's MvxPresenterHelper class is gluing the ViewModels together with the ContentPages. But the class is not using the provided IoC container from MvvmCross (Mvx) and is also doing the reflection process by itself, not providing the ability to inject dependencies into the Views.
I rewrote the Helper class to use the MvvmCross IoC container itself. You still have the ability to use other containers without changing your helper code. Reflection will be minimized because you don't need to scan the whole assembly, just the namespace where the Pages are stored.
MvxPresenterHelper.cs
public static ContentPage CreatePage(MvxViewModelRequest request)
{
var viewModelName = request.ViewModelType.Name;
var pageName = viewModelName.Replace("ViewModel", "Page");
Type pageType = Type.GetType(App.PageNamespace + "." + pageName);
if (pageType == null)
{
Mvx.Trace("Page not found for {0}", pageName);
return null;
}
var page = Mvx.Resolve(pageType) as ContentPage;
if (page == null)
{
Mvx.Error("Failed to create ContentPage {0}", pageName);
}
return page;
}
Notice the App.PageNamespace property. It stores the specific namespace for the ContentPages.
You need to register your pages in the App.cs
public class App : MvxApplication
{
public static string PageNamespace { get; private set; }
public App()
{
PageNamespace = this.GetType().Namespace + ".Pages";
}
public override void Initialize()
{
// Mvx default registration here
// Register all ContentPages
this.CreatableTypes()
.EndingWith("Page")
.InNamespace(PageNamespace)
.AsTypes()
.RegisterAsDynamic();
this.RegisterAppStart<MainViewModel>();
}
}