MasterDetail页面汉堡菜单没有显示

时间:2017-06-27 15:28:54

标签: c# xamarin menu xamarin.forms master-detail

我在我的项目中实现了显示汉堡菜单的代码,但出于某种原因,我只能看到幻灯片上的菜单(从左到右),但无法看到汉堡包(或任何)图标。

这是我的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);
        }
    }
}

最后截图:

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

您不应在导航页面内使用MasterDetail页面。

您可以尝试以下更改:

  1. 将登录页面设置为验证用户身份的根目录。用户通过身份验证后,将root设置为主详细信息页面。
  2. 如果您需要从详细信息页面进一步导航,请在导航页面中打包您的详细信息页面。
  3. 详细了解主要详细信息页面,并查看提供的示例 - Master-Detail Page

答案 1 :(得分:0)

请检查以下

  1. 更新MasterDetail页面的详细信息部分
  2.   

    块引用

     <MasterDetailPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <local:MyHomePage/>
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>
    

    即。你需要用“NavigationPage”标签包装你的“MyHomePage”

    1. 在MasterDetail页面的代码文件中,即MenuPage。在构造函数中放入以下行

          NavigationPage.SetHasNavigationBar(this, false);
          NavigationPage.SetHasBackButton(this, false);
      
    2. 在MyHomePage的代码文件中。删除构造函数

      中的以下代码行
          NavigationPage.SetHasBackButton(this, false);
      
相关问题