我正试图创建一个汉堡菜单,但当我启动应用程序时,我得到了一个空页面。我正在使用Prism开发这个android应用程序,我遵循了这篇文章:https://dansiegel.net/post/2017/04/01/the-hamburger-menu-with-prism-forms但对我来说,这行不通。
主页.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>
主页.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();
}
}
}
主页视图模型
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";
}
}
}
有人知道发生了什么事吗?我使用的是棱镜7.2版。提前感谢
据我所见,您正在分配MasterPage,但似乎没有分配详细信息页面,这反过来又会使您的屏幕变空!尝试为其分配详细信息页面
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>