简体   繁体   中英

Prism Xamarin Forms Tabbed Page Navigation

I have a Xarmarin Forms application using Prism and Unity and am having trouble with navigation to a tabbed page.

I'm using the following versions: Prism.Forms v6.1.0-pre5 Prism.Unity.Forms v6.2.0-pre5 Xamarin.Forms v2.3.0.38-pre2

My tabbed page looks like this

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
         prism:ViewModelLocator.AutowireViewModel="True"
         xmlns:local="clr-namespace:ServiceOrdersMobileApps.Views;assembly=ServiceOrdersMobileApps"
         x:Class="ServiceOrdersMobileApps.Views.ServiceOrderTabs">
 <NavigationPage Title="Summary">
  <x:Arguments>
    <local:ServiceOrderSummary />
  </x:Arguments>
 </NavigationPage>
 <NavigationPage Title="Complete">
  <x:Arguments>
    <local:ServiceOrderDetails />
    </x:Arguments>
  </NavigationPage>
</TabbedPage>

I'm trying to navigate to the tabbed page with the Service Order Detail Page selected but when I navigate according to this blog post . It navigates past the tabbed page to a separate Service Order Detail Page

 var p = new NavigationParameters();
 p.Add("serviceorder", context);
 await _navigationService.NavigateAsync($"{nameof(ServiceOrderTabs)}/{nameof(ServiceOrderDetails)}",p);

You have the page wrapped in a generic NavigationPage that Prism doesn't know about. You need to create a derived NavigationPage and register it for navigation. Then use that to wrap your COntentPages. Then you can try navigating like "ServiceOrdersTabs/MyNavigationPage/ServiceOrdersDetails".

But even this may not work now that I think about it, because you'll have multiple instances of the same NavigationPage and Prism will use the first one it finds and use that.

For a work around, you'll have to create a different NavigationPage for each tab (ServiceOrderSummaryNavPage, ServiceOrdersDetailsNavPage, etc) to ensure that each Tab is unique.

By the way, from where are you navigating?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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