question

StefanoM-9408 avatar image
0 Votes"
StefanoM-9408 asked JarvanZhang-MSFT commented

Insert the link to the pages inside a TabViewItem

I have created a TabView and for each icon I am trying to insert as content the pages I created previously. I can't insert them inside the TabViewItem, visualStudio reports me as an error.

My pages are inside the 'Pagine' folder in Visual Studio
Screen

 <xct:TabViewItem
                 TabWidth="{Binding TabWidth}"
                 Text="Home"
                 FontFamily="MyIcon"
                 ControlTemplate="{StaticResource TabItemTemplate}">
             <xct:TabViewItem.Icon>
                 <FontImageSource  Color="Gray" FontFamily="MyIcon" Glyph="{x:Static dayr:FontIconClass.Home}"/>
             </xct:TabViewItem.Icon>
             <xct:TabViewItem.IconSelected>
                 <FontImageSource  Color="Black" FontFamily="MyIcon" Glyph="{x:Static dayr:FontIconClass.Home}"/>
             </xct:TabViewItem.IconSelected>
    
              //ERROR
           <Myapp:MainPage></Myapp:MainPage>     
             </xct:TabViewItem>

The error is:

Property 'Content' does not support values of type 'MainPage'

dotnet-xamarin
immagine.png (65.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

The error is: Property 'Content' does not support values of type 'MainPage'

The xct:TabViewItem control is type of TemplatedView, we cannot place a contentPage inside it. It supports to use the ContentView, try using a contentView instead.

<xct:TabViewItem
    TabWidth="{Binding TabWidth}"
    Text="Home"
    FontFamily="MyIcon">
    ...
    <local:View1 />
</xct:TabViewItem>

Related doc about the Xamarin Community Toolkit TabView: https://devblogs.microsoft.com/xamarin/xamarin-community-toolkit-tabview/

Best Regards,

Jarvan Zhang



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.


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I still don't know how to solve the problem. If the control only supports a ContentView how can I insert a ContentPage into it?

0 Votes 0 ·

To be able to use the TabView functionality but with the pages inside, do I have to create a custom control? The TabbedPage doesn't allow much customization

0 Votes 0 ·

We cannot put a contentPage inside another directly. Maybe the Shell application template can meet your requirement.

<?xml version="1.0" encoding="utf-8" ?>
<Shell ...x:Class="App19F_Shell2.AppShell">
    ...
    <TabBar>
        <Tab Title="page_1" >
            <ShellContent ContentTemplate="{DataTemplate local:Page1}" />
        </Tab>
        <Tab  Title="page_2">
            <ShellContent ContentTemplate="{DataTemplate local:Page2}" />
        </Tab>
    </TabBar>
</Shell>

84677-image.png

Tutorial: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/

0 Votes 0 ·
image.png (140.3 KiB)

I looked around for a while, but with a Shell is there this kind of customization? Or will I have to use another way yet?Example


0 Votes 0 ·
Show more comments