2
votes

According to MvvmCross 5.3 documentation you can mix Xamarin.Forms and Xamarin.Native:

"With MvvmCross 5.3, you will now be able to mix and match Native Xamarin views with Xamarin.Forms pages using ViewModel navigation!"

My scenario is the solution contains Xamarin.Android and Xamarin.iOS projects which rely quite heavily on MvvmCross. Going forward I would like to be able to create new views/pages using Xamarin.Forms. I'm assuming this is what is meant by "mix and match".

Other than the above statement I can't find any documentation or examples on how to do this.

I tried extending the MvvmCross TipCal app to show a new Xamarin.Forms view/page without any luck.

Can someone explain or provide an example of how to mix and match Xamarin.Forms with Native Xamarin using MvvmCross?

1
Is there a reason you want to use MVVMCross? It's amazing, but you can add Xamarin.Forms without MVVMCross as you can see here docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/…Saamer
Unfortunately, our applications are quite mature and it would take quite a lot of effort to rewrite to use Xamarin.Forms only.Steven Bruce
I understand that Bruce, but I was trying to say is that you don’t need to use a framework like MVVM cross in order to do what you want. I am doing the same thing with one of my Xamarin applications that has a lot of Xamarin native code. Are you saying that you guys already use MVVVM cross in your application?Saamer
Yeah, that's right. We have an existing solution that consists of a Xamarin.iOS and Xamarin.Android projects. Both rely quite heavily on MvvmCross - I'll update the question to reflect this. Thanks.Steven Bruce
@StevenBruce This is the question of the century. I've spent quite literally three days in a row trying to mix views and despite the MVVMCross blog saying "it's easy" I've yet to see it work. Extremely frustrating that there's no examples out there after years of supporting this and even the TipCalc project doesn't do it. Did you ever figure this out?znelson

1 Answers

0
votes

I think if you truly want to mix forms/native you need to either create a custom view presenter or trick the existing view presenter to "embed" a forms page into a viewcontroller/fragment/activity.

I have created a helper library as a proof of concept to embed Xamarin.Forms content pages into fragments/activities/viewControllers but could use some help ironing out some bugs with Android. It seems to work fine for iOS.

Let's take iOS as an example. This approach has you create you content page as normal, but also create a wrapper viewController. You embed the content page in the viewController and when you navigate, you navigate to the viewController wrapper instead of the content page.

https://github.com/dornerworks/Mvx.Forms.PageWrapper.iOS

https://github.com/dornerworks/Mvx.Forms.PageWrapper.Android