0

I'm trying to add icons to my tabs with font awesome, in my Xamarin iOS/android app, I looked in many tutorials and I tried to do the same but something is wrong with the following code:

<TabbedPage.Children>

       <mypages:List Title="Lista">
           <Tab.Icon>
               <FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="&#xf2bb;" Size="Small" />
           </Tab.Icon>
       </mypages:List>

</TabbedPage.Children>

Everything worked until I add the <Tab.Icon> Stuff.

1 Answers1

1

The error you got is self-explanatory:

"The attachable property "Icon" was not found in type 'Tab' ", with <Tab.Icon> underlined.

There is no property called Icon in type Tab, you can use below but as you can see, it is IconImageSource which requires to provide a resource image name and not a font glyph.

<TabbedPage.Children>
        <apptest:Page2 IconImageSource="imageName.png"/>
</TabbedPage.Children>

An alternative in order to use font icons would be to use Shell to build your tabs instead of TabbedPage, which provides font icon support thru FontImageSource:

<Shell>
...
<Tab Title="title">
   <Tab.Icon>
         <FontImageSource FontFamily="FontAwesome" Glyph="{x:Static fonts:IconFont.AddressBook}"/>
   </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate local:Page1}"/>
</Tab>

Details about fontawesome in xamarin.forms: How to use Font Awesome icons in project as an icon of ImageButton

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • And how do I connect an existing XAML to that tab? the same way? –  Feb 17 '21 at 22:22
  • As you probably in Shell docs it is a different syntax/hierarchy, o you will probably need to spend some time (more or less depending on your app size) to migrate toward Shell. [Shell.Tabs](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/tabs) – Cfun Feb 17 '21 at 22:27
  • 1
    @Cfun Your answer resolved my conflict, thank you – jon.nicholssoftware.com Mar 24 '22 at 02:07