我在我的项目中实现了显示汉堡菜单的代码,但出于某种原因,我只能看到幻灯片上的菜单(从左到右),但无法看到汉堡包(或任何)图标。
这是我的MenuPage.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"
x:Class="LoginSystem.Views.MenuPage"
xmlns:local="clr-namespace:LoginSystem.Views">
<MasterDetailPage.Master>
<ContentPage Title="Menu" >
<StackLayout Orientation="Vertical" BackgroundColor="LightBlue">
<Button Text="Calendar" BackgroundColor="Blue" TextColor="White" HorizontalOptions="FillAndExpand" Command="{Binding Calendar_OnClicked}"/>
<Button Text="My Profile" BackgroundColor="Blue" TextColor="White" HorizontalOptions="FillAndExpand" Command="{Binding MyProfile_OnClicked}"/>
<Button Text="Home" BackgroundColor="Blue" TextColor="White" HorizontalOptions="FillAndExpand" Command="{Binding MyHome_OnClicked}"/>
<Button Text="Logout" BackgroundColor="Blue" TextColor="White" HorizontalOptions="FillAndExpand" Command="{Binding Logout_OnClicked}"/>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:MyHomePage/>
</MasterDetailPage.Detail>
</MasterDetailPage>
这是我的MenuPage.cs:
using LoginSystem.Models;
using LoginSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace LoginSystem.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MenuPage : MasterDetailPage
{
public MenuPage(string email, string password)
{
InitializeComponent();
NavigationPage.SetHasBackButton(this, false);
this.BindingContext = new Menu_vm(email, password);
}
public MenuPage()
{
InitializeComponent();
NavigationPage.SetHasBackButton(this, false);
this.BindingContext = new Menu_vm();
}
}
}
您在(Xaml)背景中看到的页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ViewModels="clr-namespace:LoginSystem.ViewModels"
xmlns:local="clr-namespace:LoginSystem.Views"
x:Class="LoginSystem.Views.MyHomePage"
BackgroundColor="Azure"
Title="My Home Page">
<ContentPage.Content>
<StackLayout>
<Label Text="{Binding Welcome}" HorizontalOptions="Center" TextColor="Gold" FontSize="Large"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
.CS:
namespace LoginSystem.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyHomePage : ContentPage
{
public MyHomePage(string email, string password)
{
InitializeComponent();
NavigationPage.SetHasBackButton(this, false);
this.BindingContext = new MyHomePage_vm(email, password);
}
public MyHomePage()
{
InitializeComponent();
NavigationPage.SetHasBackButton(this, false);
}
}
}
最后截图:
答案 0 :(得分:0)
您不应在导航页面内使用MasterDetail页面。
您可以尝试以下更改:
详细了解主要详细信息页面,并查看提供的示例 - Master-Detail Page
答案 1 :(得分:0)
请检查以下
块引用
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:MyHomePage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
即。你需要用“NavigationPage”标签包装你的“MyHomePage”
在MasterDetail页面的代码文件中,即MenuPage。在构造函数中放入以下行
NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);
在MyHomePage的代码文件中。删除构造函数
中的以下代码行 NavigationPage.SetHasBackButton(this, false);