Xamarin Forms - 在 MasterDetailPage 中隐藏导航栏 [英] Xamarin Forms - Hide navigation bar in MasterDetailPage

查看:32
本文介绍了Xamarin Forms - 在 MasterDetailPage 中隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 xamarin 表单 3.0 中隐藏导航栏.

我尝试了这个,但不起作用:

解决方案

detail 页面上,您必须使用 NavigationPage.SetHasNavigationBar(this, false);InitializeComponent()

之后的构造函数中

公共部分类 MyPage : NavigationPage{公共我的页面(){初始化组件();NavigationPage.SetHasNavigationBar(this, false);}}

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:

解决方案

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);
    }
}

这篇关于Xamarin Forms - 在 MasterDetailPage 中隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆