0
votes

I have a master detail page as the root page for my application. As a detail page for that I have a tabbed page. In the tabbed page I have a content page and a navigation page containing one content page. In the master detail's OnNavigatedTo I'm retrieving some organisation data from the cloud and then I want to navigate to a manage organisation page which is the plain content page in the tabbed page.

Using NavigateAsync and a relative uri to the manage organisation page I find that the Tabbed Page OnNavigatedTo is hit twice and then I get an exception such as (simplified) below. I can also see Binding errors in my output showing that elements on my manage organisation page xaml tried to bind to the tabbed page view model.

I'm not sure if this is an issue with the view model auto wire change in 6.2 or if it's a deep linking issue or if I've done something wrong.

"Sequence contains no elements".

at System.Linq.Enumerable.Last[TSource] (IEnumerable`1 source) [0x00079] 
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnAttachedToWindow () [0x00011]
in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:189

Using XF 2.3.1.114, Prism.Forms 6.2, I'm not sure if other packages are relevant. If you think so I can include them.

Also interestingly, it works if I try navigate to the content page in the navigation page from the master detail i.e. "TabbedPage/NavigationPage/ContentPage".

Any ideas what the problem might be?

1
There are a lot of moving pieces here and a complicated page structure. It can be any number of things causing your issue. Can you provide a small sample that reproduces the issue? Also, make sure all your pages are registered for navigation. If you have a Page in your TabbedPage that isn't registered then it won't be able to find it.user5420778
@BrianLagunas Thanks for your reply. I created a sample here which replicates the issue at least on my machine. github.com/Troto/PrismJunkAppTroto
I'm trying to work around it by navigating to a different page and then just tabbing back but it appears that the view model isn't wired up to the view. So there's not much I can do with that page.Troto

1 Answers

1
votes

So first thing first, you don't have the proper XAML syntax for your TabbedPage. When defining the default page for a NavigationPage in XAML you must supply the page via the Arguments element:

  <views:SimpleNavPage Title="Foo">
       <x:Arguments>
            <views:NestedContentPage />
       </x:Arguments>
  </views:SimpleNavPage>

You must also have the proper ctor in your navigation page:

    public SimpleNavPage(Page root) : base (root)
    {
        InitializeComponent();
    }

Now, I personally don't recommend navigating within the OnNavigatedTo unless you can absolutely guarantee that you will not be adding that page in another deep link, or navigation scenario. Imagine you start out with NavigateAsync("MainPage") and that has an OnNavigatedTo that does a deep link navigation operation. Now you decide to NavigateAsync("SomeOtherPage") in which it NavigateAsyc("AnotherPage/MainPage/SomeOtherPage/LastPage") from within it's OnNavigatedTo. Now, you will have created an issue because the MainPage.OnNavigatedTO will have kicked off another navigation operation while you are still navigating to the next "SomeOtherPage". You are asking for trouble.