首页 > 解决方案 > 如何在 C# 中为 ContentPage 设置 Shell.NavBarIsVisible="false"?

问题描述

这是我拥有的 XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    Shell.NavBarIsVisible="false"
    xmlns ="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Test.ABC" >

我正在尝试在 C# 中重新创建它,但遇到了一个问题,因为这些方法都不起作用:

namespace Test
{

    public partial class ABC : ContentPage
    {
        Shell.NavBarIsVisible = false;

        public ABC()
        {
            Shell.SetNavBarIsVisible = false;
            Shell.NavBarIsVisibleProperty = false;

有谁知道我如何在没有 XAML 文件的 C# 实现中做到这一点。

标签: xamarinxamarin.forms

解决方案


您需要在 Method 中调用它们OnAppearing

在内容页面

protected override void OnAppearing()
{
   base.OnAppearing();
   Shell.SetTabBarIsVisible(this, false);
   Shell.SetNavBarIsVisible(this, false);
}

注意:如果您只想在特定的 ContentPage 中隐藏 Tabbar 和 NavigationBar ,请不要忘记在离开页面时显示它们

protected override void OnDisappearing()
 {
   base.OnDisappearing();
   Shell.SetTabBarIsVisible(this, true);
   Shell.SetNavBarIsVisible(this, true);
}

推荐阅读