Inam
Inam

Reputation: 39

Using Xamarin.Forms with Native pages (Xamarin.iOS, UWP)

I already have a solution which consist of Xamarin.iOS and UWP. We have multiple views (Pages) in both platforms. We are using MvvmCross, so we have a common code (PCL) which consists of Viewmodels, business logic etc. Also, we have separate views (Pages) for both Xamarin.iOS and UWP.

Now I want to add Xamarin.Forms support for native pages of both projects so that we have same views for both Xamarin.iOS and UWP. We need the support of navigation (from Native to Xamarin.Forms & vice versa). I am navigating through MvvmCross navigation service.

For instance, I have FirstFormView in Xamarin.Forms project. I have SecondFormView in Native project (can be Xamarin.iOS or UWP). I have ThirdFormView in Xamarin.Froms project.

I have navigated to FirstFormView (which is staring page of my application) Now I want to go to SecondFormView (which is in native project). And from SecondFormView I need to go to ThirdFormView which is again in Xamarin.Forms

Is it possible to do it MvvmCross? If yes, then what steps should we follow to achieve our desired goal.

Thanks in advance.

Regards,

Upvotes: 2

Views: 709

Answers (2)

Martijn00
Martijn00

Reputation: 3559

This is possible through the Forms presenters. Take a look at the playground: https://github.com/MvvmCross/MvvmCross/tree/develop/TestProjects/Playground/Playground.Forms.Droid

Here the views are all Forms, but 1 or 2 are in Native. By using the same solution you should be able to do this.

Upvotes: 2

Umair M
Umair M

Reputation: 10720

You already have MvvmCross in your PCL project, just need to add Xamarin Form pages (XAML) for every page in platform specific project (iOS, UWP). And custom renderers for every platform.

For example:

//in xamarin forms pcl project
namespace XFormProject
{
    public class MyXFormPage : ContentPage project
    {

    }
}

// in ios project
namespace XFormProjecy.iOS
{

    [assembly:ExportRenderer(typeof(XFormProject.MyXFormPage), typeof(XFormProject.iOS.MyXFormPageIOS))]
    public class MyXFormPageIOS : PageRenderer // in iOS
    {
        // your ios native page code goes here.
    }
}

Read more about Custom Rederers

Hope this helps :)

Upvotes: 1

Related Questions