【问题标题】:Xamarin Forms - Hide navigation bar in MasterDetailPageXamarin Forms - 在 MasterDetailPage 中隐藏导航栏
【发布时间】:2018-12-10 17:57:08
【问题描述】:

我需要在 xamarin forms 3.0 中隐藏导航栏

我试试这个,但不工作: Hide Navigation Bar on MasterDetailPage

我想隐藏导航栏以创建自定义栏,我还需要一种打开菜单的方法。 谢谢。

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>

源代码库: https://github.com/uiahhh/stackoverflow/tree/master/HideNavBar

我想删除这个红色圆圈中的导航栏:

【问题讨论】:

  • 您应该将相关代码放在 StackOverflow 上的问题中。
  • @Cheesebaron 我放了代码和屏幕。 :)

标签: xamarin xamarin.forms xamarin.ios xamarin.android


【解决方案1】:

detail 页面上,您必须在 InitializeComponent() 之后的构造函数中删除带有 NavigationPage.SetHasNavigationBar(this, false); 的导航栏

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

【讨论】:

    【解决方案2】:

    除了Pedro's answer,您还可以隐藏.xaml 文件中的导航栏。例如:

    <ContentPage NavigationPage.HasNavigationBar="False">
        ...
    </ContentPage>
    

    注意:这适用于 Xamarin 4.0,但我尚未在 3.0 中对其进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2017-07-23
      • 1970-01-01
      • 2018-11-09
      • 2016-09-29
      • 2021-10-20
      • 2017-01-24
      相关资源
      最近更新 更多