Enable navigationbar or create a panel on top of tabpage xamarin.form

2

I have this page (TabbedPage) that creates two tabs:

<?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>

What happens is that I'm not able to enable NavigationBar or at least create a panel above the tabpages . The ideal would be to enable NavigationBar , this would be ideal for me. How it works. When you open App , it drops to a login screen. When you log in, you enter MainPage and TabPages on it. If I try to exclude NavigationBar it does not give any errors, but it does not display. Either she is hide or the TabPages are "killing" her. Below my codes. MainPage

[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : TabbedPage
    {
        public MainPage ()
        {
            InitializeComponent ();
            NavigationPage.SetHasNavigationBar(this, true);            
        }
    }

the login screen

public  void Login_Clicked(object sender, EventArgs e)
        {
            LoginService svc = new LoginService();
            LoginRS res = svc.Login(txtUsuario.Text, txtSenha.Text);
            if (res != null && res.Success  )
            {
                App.LooggedUser = res;
                Application.Current.MainPage = new MainPage();
            }
            else if(res != null && ! res.Success)
            {
                lblErroLogin.Text = res.Exception;
            }
            else
            {
                lblErroLogin.Text = "Não foi possível realizar o Login, por favor verifique sua conexão com a Internet";
            }
        }

and my App.xaml.cs

public App()
        {
            InitializeComponent();

            if (!IsUserLoggedIn)
            {
                MainPage = new NavigationPage(new LoginPage());
            }
            else
            {
                MainPage = new NavigationPage(new MainPage());
            }
        }
    
asked by anonymous 07.02.2018 / 20:08

1 answer

1

Dude, this is a tricky subject. Although it is possible, it is not recommended.

The implementation would be to change the code of the login button, where you change the MainPage of the app, to put TabbedPage within NavigationPage the same way you did in else OnStart like this:

public  void Login_Clicked(object sender, EventArgs e)
{
    LoginService svc = new LoginService();
    LoginRS res = svc.Login(txtUsuario.Text, txtSenha.Text);
    if (res != null && res.Success  )
    {
        App.LooggedUser = res;
        Application.Current.MainPage = new NavigationPage(new MainPage());
    }
    else if(res != null && ! res.Success)
        lblErroLogin.Text = res.Exception;
    else
        lblErroLogin.Text = "Não foi possível realizar o Login, por favor verifique sua conexão com a Internet";
    }
}

And when navigating from there, use Navigation from the main page instead of Navigation from TabbedPage :

App.Current.MainPage.Navigation.PushAsync(new NovaPage());

About not being recommended:

Since Xamarin.Forms is multi-platform, it is important that you write your Apps so that usability is "fluent" in each of them at the time of execution.

In this specific case, as you can see this site article of Xamarin developers , we would have a problem with the iOS interface.

In a free translation of the site alert:

  

Although it is sensible to admit NavigationPages inside the TabbedPage, we do not recommend that you put a TabbedPage inside a NavigationPage, because in iOS the UITabBarController always acts as a package for the UINavigationController.

In this quote the site recommends checking the guideline for this subject: Combined View Controller Interfaces .

I hope it helps.

    
08.02.2018 / 00:17