Xamarin Forms - Hide navigation bar in MasterDetai

2019-07-14 20:33发布

问题:

I need hide navigation bar in xamarin forms 3.0.

I try this, but dont work: Hide Navigation Bar on MasterDetailPage

I want hide navigation bar for create a custom bar, also I need a way to open menu. Thanks.

App.xaml.cs

public partial class App : Application
{
    public App ()
    {
        InitializeComponent();

        MainPage = new MainPage();
    }
...

MainPage.xaml.cs

public partial class MainPage : MasterDetailPage
{
    public List<MasterPageItem> menuList { get; set; }
    public MainPage()
    {
        InitializeComponent();

        menuList = new List<MasterPageItem>();

        menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(HomePage) });
        menuList.Add(new MasterPageItem() { Title = "Settings", Icon = "setting.png", TargetType = typeof(SettingsPage) });
        menuList.Add(new MasterPageItem() { Title = "Help", Icon = "help.png", TargetType = typeof(HelpPage) });

        navigationDrawerList.ItemsSource = menuList;

        var navPage = new NavigationPage((Page)Activator.CreateInstance(typeof(HomePage)));

        //I try this:
        NavigationPage.SetHasNavigationBar(navPage, false);
        NavigationPage.SetHasBackButton(navPage, false);

        Detail = navPage;
    }
...

MainPage.xaml

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

    <MasterDetailPage.Master>
        <ContentPage Title="Menu">
            <Grid BackgroundColor="Transparent">
                <StackLayout Grid.Row="1" Spacing="15">
                   ...
                </StackLayout>
            </Grid>
        </ContentPage>
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>

        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

Source repo: https://github.com/uiahhh/stackoverflow/tree/master/HideNavBar

I want remove this navbar in red circle:

回答1:

On the detail page you have to remove the navigation bar with NavigationPage.SetHasNavigationBar(this, false); in the constructor right after InitializeComponent()

public partial class MyPage : NavigationPage
{
    public MyPage()
    {
        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);
    }
}