不显示带有Prism和xamarin形式的汉堡菜单

问题描述 投票:0回答:1

我正在尝试创建一个汉堡菜单,但是当我启动该应用程序时,我得到一个空白页面。我正在使用Prism开发此android应用程序,并且关注了这篇文章:https://dansiegel.net/post/2017/04/01/the-hamburger-menu-with-prism-forms但对我而言,它不起作用。

MainPage.cs

<?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="HomeManagement.Views.MainPage">
    <MasterDetailPage.Master>
        <!-- Hamburger Menu Secret Sauce... Add an Icon!!!! Make sure it's in your resources for your Platform Project -->
        <NavigationPage Title="Required Foo" Icon="ic_launcher.png">
            <x:Arguments>
                <ContentPage Title="Menu">
                    <StackLayout Padding="40">
                        <Label Text="Test hello" />
                        <Button Text="HuePage"/>
                    </StackLayout>
                </ContentPage>
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Master>
</MasterDetailPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace HomeManagement.Views
{
    public partial class MainPage : MasterDetailPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
}

MainPageViewModel

using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HomeManagement.ViewModels
{
    public class MainPageViewModel : ViewModelBase
    {
        public string UserName { get; set; }

        public MainPageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Title = "Main hamburger";

        }
    }
}

任何人都知道这是怎么回事?我使用的是Prism 7.2版。在此先感谢

xamarin.forms prism
1个回答
1
投票

据我所知,您正在分配一个母版页,但是您似乎并没有在分配一个详细页面,从而使您的屏幕空白!尝试为其分配详细信息页面

MainPage mainPage = new MainPage();
mainPage.Detail= new DetailPage();

或来自XAML

 <MasterDetailPage.Detail>
       <ContentPage Title="Detail">
                <StackLayout Padding="40">
                    <Label Text="Test hello" />
                    <Button Text="HuePage"/>
                </StackLayout>
            </ContentPage>
 </MasterDetailPage.Detail>
© www.soinside.com 2019 - 2024. All rights reserved.