Using MvvmCross to link Xamarin Native page and Xamarin Forms page

MvvmCross is a powerful framework, which can be used on Xamarin.IOS, Xamarin.Android and WP. We can use it to binding data, navigation, etc. But it cannot help us to share the UI codes. For example, if we want to build login page, we can use MvvmCross to build the data layer. We need to build a login page for Android, and another page for IOS.

Xamarin Forms can share the UI codes, it means we can build only one login page in Xamarin Forms, and use it both in Android and IOS. Generally speaking, if our project pages are all data, images, something with basic logic, we can use Xamarin Forms pages to build the whole solution.  But if this project use like camera, video/audio player, maps, then Xamarin Forms cannot help us to build these pages.

In our last project, the solution used camera, so that for some basic pages it have to use native pages. As MvvmCross cannot navigate between native page and Xamarin Forms page by default.

But we changed it, as MvvmCross has a outstanding architecture, we write a extension to achieve this. Here is demo

https://github.com/jessejiang0214/MvvmCrossNavigationDemo

For this demo, some steps are import.

  1. Included Xamarin.Forms packages into IOS and Android Project
  2. Init Xamarin.Forms, for IOS, it is in Setup.cs. But in Android, it is in SplashScreen page, if your project doesn’t have that page, you should make sure Xamarin.Forms.Init() before show Xamarin Forms page.
  3. Copy MvxTouchViewPresenter MvxPresenterHelpers MvxFormsDroidPagePresenter pages into your project. For Android project, you need create MvxFormsApplicationActivity, because Xamarin Forms need a host activity in Android.

We didn’t do the same thing in Windows Phone, because Xamarin Forms only support Windows Phone Silverlight in currently version (1.4.4). I don’t like Windows Phone Silverlight, so I just wait for Xamarin Forms support Windows RT, and then use it.

Hope you can enjoy our demo, and build amazing apps based on Xamarin Forms and MvvmCross.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s