0
votes

Situation: Building an application using Xamarin Forms and MasterDetail component.

Question: How Can I render a specific page on Android based on a PageRender? and keep the Drawer?

Edit

public class MasterBacASable : MasterDetailPage
{
    public MasterBacASable ()
    {
        Icon = null;
        Title = "The title";
        Detail =  (new FirstPage ());
        Master = new AppMenuPage ();
    }
}

[assembly:ExportRenderer (typeof(BacASable.FirstPage), typeof(BacASable.Droid.FirstPageContentRennderer))] namespace BacASable.Droid { public class FirstPageContentRennderer : PageRenderer { public FirstPageContentRennderer () {
}

    protected override void OnElementChanged (ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged (e);
        var activity = this.Context as Activity;
        var v = activity.LayoutInflater.Inflate (Resource.Layout.AndroidView,this,false);
        AddView (v);
    }
}

}

2

2 Answers

0
votes

Follow this for Xamarin.Forms Master-Detail Documentation

The base Concept is the following

public class MainPageCS : MasterDetailPage
{
    MasterPageCS masterPage;

    public MainPageCS ()
    {
        masterPage = new MasterPageCS ();
        Master = masterPage;
        Detail = new NavigationPage (new ContactsPageCS ());
        ...
    }    
}

Your Master is your drawer and Detail the Page (ContentPage, TabbedPage,NavigationPage,CustomPageRenderer ).

So each time you want to display a different page set the Detail property

Detail = new MyContentPage();
0
votes

I was just forgetting to override the OnLayout in the Renderer. Thank you all.