Xamarin Forms导航到内容页面之后的MasterDetail页面 [英] Xamarin Forms navigating to a MasterDetail Page after a Content Page

查看:75
本文介绍了Xamarin Forms导航到内容页面之后的MasterDetail页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin Forms创建一个应用程序,在该应用程序中,当用户首次启动应用程序时,会将它们发送到登录页面.他们登录后,将被重定向到MasterPage,即MasterDetail页面.但是,当我尝试导航到新的MasterDetail页面时,我仅获得了Detail页面,并且缺少显示Master Portion的按钮.应用栏上唯一出现的是我设置的标题.我目前正以这种方式进入MasterPage:

I'm creating an app using Xamarin Forms where when a user launches an app for the first time, they are sent to a login page. Once they log in, they're redirected to the MasterPage, which is a MasterDetail Page. However, when I try to navigate to the new MasterDetail Page, I only get the Detail Page, and the button to show the Master Portion is missing. The only thing appearing on the app bar is the title I set. I'm currently going to the MasterPage like this:

App.Current.MainPage = new NavigationPage(new MasterPage())
{
     Title = "Welcome " + user.firstName
};

对于其他所有运行,这都不是问题,因为当用户打开应用程序时,它会自动将其登录并直接进入MasterPage,除非在首次使用时.但是,这对我来说是一个非常重要的问题,因为它是在用户第一次使用我的应用程序时发生的,这将是他们的第一印象.

Every other run, this isn't an issue, since when a user opens the app it automatically logs them in and goes right to the MasterPage, except during their first use. However, this is a very important issue for me since it happens the first time a user uses my app and it will be part of their first impression.

推荐答案

使用MasterDetailpage时,不应将其包装到Navigationpage中(如您的代码示例).因为MasterDetailPage每次都应该放在顶部,而不是在NavigationPage内部.

When you use a MasterDetailpage, you should not wrap it into a Navigationpage (like your code-example). Because the MasterDetailPage should everytime be on top and not inside a NavigationPage.

要在不同页面之间导航,应将DetailPageMasterDetailPage包裹在NavigationPage内.

To navigate between different pages you should wrap your DetailPage from the MasterDetailPage inside a NavigationPage.

这里有一些代码需要澄清:

Here some code for clarification:

var view = new MyFirstPage();
Application.Current.MainPage = new MasterPage(view);

在MasterPage构造函数中,执行以下操作:

And inside the MasterPage constructor, do the following:

public MasterPage(Page detailpage)
{
    // Set the master-part
    Master = new MasterContentPage();

    // Set detail-part (with a navigation page)
    Detail = new NavigationPage(detailpage);
}

然后,您可以使用以下导航在应用内部导航:

And after that, you can navigate inside your app with this navigation:

var mdp = Application.Current.MainPage as MasterDetailPage;
await mdp.Detail.Navigation.PushAsync(myNextPage);

我通常创建一个静态助手类AppNavigator来完成这些工作.

I usually create a static helper class AppNavigator to do this stuff.

有关更多信息,请参见 Xamarin开发人员指南上的MasterDetailPage说明.

For further information, look at the MasterDetailPage instructions on the Xamarin developer guides.

这篇关于Xamarin Forms导航到内容页面之后的MasterDetail页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆