How to create a hamburger menu with a MainPage inheriting from TabbedPage?

1

I'm having a hard time creating a hamburger menu because my MainPage inherits from TabbedPage . Is there a way to do this with a TabbedPage ? To create this menu, we usually create two new pages ( ContentPage ) and pass MainPage to inherit from MasterDetailPage and in the MainPage constructor we do:

this.Master = new Master();
this.Detail = new NavigationPage(new Detail());

this would be the classic form. But since my MainPage inherits from TabbedPage I can not implement this. If I remove TabbedPage , I lose the page's browsability by Tabs . I do not even know if there is a way to TabbedPage from within MainPage to MasterDetailPage . Below my MainPage :

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:views="clr-namespace:Operacional.Views"
            x:Class="Operacional.Views.MainPage">


    <TabbedPage.Children>
        <NavigationPage Title="Indicadores">
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="tab_about.png"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <views:Indicadores />
            </x:Arguments>
        </NavigationPage>
        <NavigationPage Title="Paineis">
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="tab_feed.png"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <views:PaineisPage />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

and the code behind it

[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : TabbedPage
    {
        public MainPage ()
        {
            InitializeComponent ();

            NavigationPage.SetHasNavigationBar(this, true);

            //this.Master = new Master();

           // NavigationPage.BarBackgroundColorProperty. = Color.Gray;
        }
    }

If I could leave the MainPage free and run another page inside, I would also solve it, but the question is: Can I create a menu with a MainPage inheriting from TabbedPage?

Use Net Standard (Xamarin.Forms)

EDIT1

I made this code inside MainPage

public MainPage ()
        {
            InitializeComponent ();

            NavigationPage.SetHasNavigationBar(this, true);

            Application.Current.MainPage = new MasterDetailPage
            {
                Master = new Master(), ==>> aqui o erro
                Detail = new TabbedPage
                {
                    Children =
                    {
                        new NavigationPage(new Indicadores()),
                        new NavigationPage(new PaineisPage())
                    }
                }
            };

            // NavigationPage.BarBackgroundColorProperty. = Color.Gray;

        }

I get this error

    
asked by anonymous 13.02.2018 / 15:32

1 answer

0

I solved it like this:

 Application.Current.MainPage = new MasterDetailPage
                {
                    Master = new Master(),
                    Detail = new TabbedPage
                    {
                        Children =
                    {
                        new NavigationPage(new Indicadores()){ Title = "Indicadores"},
                        new NavigationPage(new PaineisPage()){ Title = "Painéis"}
                    }
                    }
                };

and pass MainPage to MasterDetailPage. This way I was able to create the menu.

    
13.02.2018 / 20:12