Xamarin表单-在MasterDetailPage中隐藏导航栏
我需要在xamarin forms 3.0中隐藏导航栏 我试过这个,但不起作用: 我想隐藏导航栏以创建自定义栏,我还需要一种打开菜单的方法。 谢谢 App.xaml.csXamarin表单-在MasterDetailPage中隐藏导航栏,xamarin,xamarin.forms,xamarin.ios,xamarin.android,Xamarin,Xamarin.forms,Xamarin.ios,Xamarin.android,我需要在xamarin forms 3.0中隐藏导航栏 我试过这个,但不起作用: 我想隐藏导航栏以创建自定义栏,我还需要一种打开菜单的方法。 谢谢 App.xaml.cs public partial class App : Application { public App () { InitializeComponent(); MainPage = new MainPage(); } ... public partial class
public partial class App : Application
{
public App ()
{
InitializeComponent();
MainPage = new MainPage();
}
...
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.cs
public partial class App : Application
{
public App ()
{
InitializeComponent();
MainPage = new MainPage();
}
...
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;
}
...
公共部分类主页面:MasterDetailPage
{
公共列表菜单列表{get;set;}
公共主页()
{
初始化组件();
menuList=新列表();
添加(新的MasterPageItem(){Title=“Home”,Icon=“Home.png”,TargetType=typeof(HomePage)});
添加(新的MasterPageItem(){Title=“Settings”,Icon=“setting.png”,TargetType=typeof(SettingsPage)});
添加(新的MasterPageItem(){Title=“Help”,Icon=“Help.png”,TargetType=typeof(HelpPage)});
navigationDrawerList.ItemsSource=menuList;
var navPage=new NavigationPage((Page)Activator.CreateInstance(typeof(HomePage));
//我试试这个:
SetHasNavigationBar(navPage,false);
NavigationPage.SetHasBackButton(navPage,false);
细节=导航页面;
}
...
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>
...
来源回购协议:
我想删除红色圆圈中的导航栏:
在详细信息页面上,您必须使用NavigationPage.SetHasNavigationBar(此项为false);
在构造函数的InitializeComponent()之后立即删除导航栏
除此之外,您还可以在.xaml
文件中隐藏导航栏。例如:
...
注意:这在Xamarin 4.0中有效,但我还没有在3.0中测试它。您应该在StackOverflow上的问题中输入相关代码。@Cheesebaron我输入了代码和屏幕。:)