TabbedPage - TabbedPage.Children, NavigationPage: Missing default constructor

Jerry Lipan 916 Reputation points
2021-12-12T05:58:29.43+00:00

Hi,

I'm Xamarin Newbies. I just learn Xamarin TabbedPage with Child as following page,

MainTabbedPage.xaml

<?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:mainPages="clr-namespace:App16Crud.Views"
             x:Class="App16Crud.Views.MainTabbedPage">




    <TabbedPage.Children>

        <NavigationPage Title="Dashboard">
            <x:Arguments>
                <mainPages:DashboardPage />
            </x:Arguments>
        </NavigationPage>

        <NavigationPage Title="Daily">
            <x:Arguments>
                <mainPages:Tab2Page />
            </x:Arguments>
        </NavigationPage>

        <NavigationPage Title="Logout">
            <x:Arguments>
                <mainPages:Tab3Page />
            </x:Arguments>
        </NavigationPage>

    </TabbedPage.Children>



</TabbedPage>

Everything is fine. All Pages added successfully

I try modified in Tab2Page.xaml.cs as following. This Page need a Parameter. See below,

Tab2Page.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using App16Crud.Models;

namespace App16Crud.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Tab2Page : ContentPage
    {
        public Tab2Page(Book book)
        {
            InitializeComponent();
        }
    }
}

It return - Missing default constructor

How MainTabbedPage.xaml call Tab2Page with default constructor? Tab2Page.xaml need parameter

Please help

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-12-13T02:33:55.64+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Please add default constructor without parameter like following code.

       [XamlCompilation(XamlCompilationOptions.Compile)]  
           public partial class Tab2Page : ContentPage  
           {  
               public Tab2Page()  
               {  
                   InitializeComponent();  
               }  
         
               public Tab2Page(Book book)  
               {  
                   InitializeComponent();  
               }  
           }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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 comments No comments

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.