简体   繁体   English

Xamarin中的MasterDetailPage和NavigationPage组合

[英]MasterDetailPage and NavigationPage combination within Xamarin

I'm creating a Xamarin application where I want to combine multiple pages, the MasterDetailPage and the NavigationPage . 我正在创建一个Xamarin应用程序,我想在其中合并多个页面, MasterDetailPageNavigationPage

My MainPage contains the MasterDetailPage , the master of the MasterDetailPage contains a list of views (custom class which stores information such as the class type, image to show and the name) the user can view. MainPage包含MasterDetailPage ,所述的主MasterDetailPage包含的观点的列表(自定义类,其存储的信息,如类类型,图像显示和名称),用户可以观看。 Those views are all ContentPage s. 这些视图都是ContentPage When an item of the list is clicked, the ContentPage gets initialized by using reflection and is then stored within the MasterDetailPage . 单击列表中的一项时, ContentPage将通过反射进行初始化,然后存储在MasterDetailPage At the moment everything has been made as Xamarin suggests. 目前,一切都按照Xamarin的建议进行。

But one of those ContentPages contains a ListView . 但是这些ContentPages包含ListView

ListView的示例

When an item has been selected, the ListView has to open a detailview and the user must be able to return to the ListView . 选择一个项目后, ListView必须打开一个detailview,并且用户必须能够返回到ListView Because of that I'm using the Navigation class and push the page within the NavigationPage , as following (binding can be done better, but it's just to get feeling with Xamarin): 因此,我正在使用Navigation类并将页面推入NavigationPage ,如下所示(绑定可以做得更好,但这只是让Xamarin体会到):

private async Task Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
        if (_detail == null)
        {
            _detail = new Detail();

        }
        _detail.BindingContext = SelectedTrack;
        await Navigation.PushAsync(new NavigationPage(_detail));
}

When done like this, the Back button is rendered above the MasterDetailPage . 完成此操作后,“ 后退”按钮MasterDetailPage上方。

NavigationPage的示例

Is there any way I can remove the 'burger' button of the MasterDetailPage when going to the ListView 's detail page? 转到ListView的详细信息页面时,有什么方法可以删除MasterDetailPage的“ burger”按钮? Or am I currently using the wrong workflow? 还是我当前使用的工作流程错误?

Set your detail page as NavigationPage. 将您的详细信息页面设置为NavigationPage。

_masterDetailPage.Detail = new NavigationPage(page);

Or 要么

MainPage = new MasterDetailPage
            {
                Master = new MyMasterPage(),
                Detail = new NavigationPage(MyHomePage())
            });

And then in your from detail view you can Navigate to your other pages by : 然后在详细视图中,可以通过以下方式导航到其他页面:

await Navigation.PushAsync(new NavigationPage(_detail));

You will see back button and not Hamburger. 您会看到返回按钮,而不是汉堡包。

Have a look at the sample . 看一下样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM