Xamarin Forms Master Detail Page 主页隐藏导航栏
Xamarin Forms Master Detail Page Main Page Hide Navigation Bar
我不知道如何在将我的应用程序主页设置为 "master-detail" 页面时隐藏导航栏。如果主从页面不是应用程序的主页面,则导航栏会正确隐藏,但无论我做什么,如果它是主页面,我都无法隐藏导航栏。
我已经在母版页、详细信息页的构造函数和两者的重写 OnAppearing 方法中尝试了以下内容,但导航栏从不隐藏。
NavigationPage.SetHasNavigationBar(这个,假的);
NavigationPage.SetHasBackButton(这个, 假的);
我也直接在 XAML 中尝试过类似的逻辑,但它从不隐藏。如果我首先将我的 MainPage 设置为另一个页面,然后只需向前导航到导航栏正确隐藏的主从页面。
任何thoughts/ideas?
对于 android 实施,将以下内容添加到您的 MainActivity.cs:
global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
对于 iOS,该过程需要自定义渲染器,但它非常基础:
public class iOSCustomMobilePageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated) {
base.ViewWillAppear(animated);
if (ViewController != null && ViewController.ParentViewController != null && ViewController.ParentViewController.NavigationController != null) {
if (ViewController.ParentViewController.NavigationController.NavigationBar != null)
ViewController.ParentViewController.NavigationController.SetNavigationBarHidden(true, false);
}
}
}
我不知道如何在将我的应用程序主页设置为 "master-detail" 页面时隐藏导航栏。如果主从页面不是应用程序的主页面,则导航栏会正确隐藏,但无论我做什么,如果它是主页面,我都无法隐藏导航栏。
我已经在母版页、详细信息页的构造函数和两者的重写 OnAppearing 方法中尝试了以下内容,但导航栏从不隐藏。
NavigationPage.SetHasNavigationBar(这个,假的); NavigationPage.SetHasBackButton(这个, 假的);
我也直接在 XAML 中尝试过类似的逻辑,但它从不隐藏。如果我首先将我的 MainPage 设置为另一个页面,然后只需向前导航到导航栏正确隐藏的主从页面。
任何thoughts/ideas?
对于 android 实施,将以下内容添加到您的 MainActivity.cs:
global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
对于 iOS,该过程需要自定义渲染器,但它非常基础:
public class iOSCustomMobilePageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated) {
base.ViewWillAppear(animated);
if (ViewController != null && ViewController.ParentViewController != null && ViewController.ParentViewController.NavigationController != null) {
if (ViewController.ParentViewController.NavigationController.NavigationBar != null)
ViewController.ParentViewController.NavigationController.SetNavigationBarHidden(true, false);
}
}
}