Xamarin.Forms - 主/详细信息页面和导航历史问题 [英] Xamarin.Forms - Master/detail page and navigation history issue

查看:344
本文介绍了Xamarin.Forms - 主/详细信息页面和导航历史问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用masterdetail页面显示菜单中的所有网页的应用程序。导航是发生在我的应用程序双向。一个来自从仪表盘菜单和第二种方式。所以,如果我导航到另一个页面,然后按BACK按钮,关闭应用程序。它不记得导航历史。
主详细页面如下:

I have an app which uses masterdetail page to show menu in all page. The navigation is happened in two way in my app. one from the menu and second way from Dashboard. so if i navigate to another page, and then press "BACK" button, it closes the application. It does not remember the navigation history. The master detail page is as below:

 public class RootPage : MasterDetailPage
    {
        public RootPage ()
        {
            var menuPage = new MenuPage ();

            menuPage.Menu.ItemSelected += (sender, e) => NavigateTo (e.SelectedItem as MenuItem);

            Master = menuPage;
            Detail = new NavigationPage (new ContractsPage ());
        }

        void NavigateTo (MenuItem menu)
        {
            Page displayPage = (Page)Activator.CreateInstance (menu.TargetType);
            Detail =    new NavigationPage (displayPage);
            IsPresented = false;
        }
    }



所以任何想法如何解决这个问题?

so any ideas how to overcome this problem?

推荐答案

像什么@斯坦 - 彼得罗夫说:你要替换的详细信息页面,而不是触发历史机制。要触发历史机制,你需要的详细信息页面的导航属性做了PushAsync(页)

Like what @Sten-Petrov said: you are replacing the detail page and not triggering the history mechanism. To trigger the history mechanism you will need to do a PushAsync(Page) on the Navigation property of the Detail page.

在你的榜样,改变的NavigateTo:

In your example, change NavigateTo:

 void NavigateTo (MenuItem menu)
 {
     Page displayPage = (Page)Activator.CreateInstance (menu.TargetType);
     Detail.Navigation.PushAsync(displayPage);
 }

这不会取代内容,但会弹出一个新页面与背部你想按钮功能。

This will not replace the content but will bring up a new page with the back button functionality you want.

如果你想回来的主从页面按钮功能,那么你就需要自定义返回堆叠过程当中,在我看来,是不值得的。只需移动到在这种情况下不同的页面/导航结构。

If you want back button functionality with the Master-Detail page then you'll need to customize the back stack process which, in my opinion, is not worth it. Just move to a different page/navigation structure in that case.

这篇关于Xamarin.Forms - 主/详细信息页面和导航历史问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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