Isn't NavigationPage allowed within a TabbedPage for iOS in Xamarin.Forms 5.x

Shantimohan Elchuri 721 Reputation points
2021-04-05T18:23:15.51+00:00

I was migrating my project to newly updated XF 5.x. Due to issues with direct update, I am creating a new solution with XF 5.0 and moving my code one by one.

In this context, my old MainPage has XAML with TabbedPage with 5 tabs as shown below:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ToDoPlus.Views.MainPage">
<!--Pages can be added as references or inline-->
<TabbedPage.Children>
<NavigationPage Title="Tab1" />
<NavigationPage Title="Tab2" />
<NavigationPage Title="Tab3" />
<NavigationPage Title="Tab4" />
<NavigationPage Title="Tab5" />
</TabbedPage.Children>
</TabbedPage>

But this is raising a run time error at the end of AppDelegate's FinishedLaunching. The error is:

System.InvalidOperationException: 'NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.'

The 'app' in the code "return base.FinishedLaunching(app, options);" is not null.

This happens only with iOS and not with Android.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
0 comments No comments
{count} votes

Accepted answer
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-04-06T06:25:12.963+00:00

    Hello,

    Welcome to Microsoft Q&A!

    As the error message states : NavigationPage must have a root page before being used(on iOS) .

    We just need to Warp a contentPage inside the NavigationPage as following

       <local:Page1/>  
           <NavigationPage Title="1" >  
               <x:Arguments>  
                   <local:Page2 />  
               </x:Arguments>  
           </NavigationPage>  
        <NavigationPage Title="2">  
               <x:Arguments>  
                   <local:Page3 />  
               </x:Arguments>  
           </NavigationPage>  
    

    Check https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page#populate-a-tabbedpage-with-a-page-collection .


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.