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
For this demo, some steps are import.
- Included Xamarin.Forms packages into IOS and Android Project
- 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.
- 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.