Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an Icon Font in Xamarin Forms TabBar

I am just getting started with Xamarin Forms, so please excuse what may well be a rookie question...

I started out with a new Shell Forms App in Visual Studio, so some code was generated for me.

There is an AppShell page which contains a TabBar control. Inside this are Tab controls were I can set my ShellContent pages.

Each Tab has an Icon property, but this apparently only accepts PNG icons.

How can I use an icon font (which is already hooked up to display icons correctly as I am using them in the content of another page) for my Tab icons in Xaml?

I am using Xamarin.Forms 4.0.0.497661

like image 331
danwellman Avatar asked Jun 26 '19 12:06

danwellman


2 Answers

You have to use FontImageSource to do that.

<Tab Title="MyTitle"> <Tab.Icon> <FontImageSource FontFamily="{StaticResource IconFont}" Glyph="&#xF00A;" Size="Small"/> </Tab.Icon> ... </Tab>

like image 118
TechWatching Avatar answered Nov 14 '22 19:11

TechWatching


The solution below worked for me.

Copied the files from fontawesome inside Assets folder

  • fa-brands-400.ttf
  • fa-regular-400.ttf
  • fa-solid-900.ttf

Important the reference "Font Awesome 5 Brands" according to icon needed

<Tab.Icon>
    <FontImageSource FontFamily="fa-brands-400.ttf#Font Awesome 5 Brands" Glyph="&#xf39e;"/>
</Tab.Icon>
like image 3
RRV Avatar answered Nov 14 '22 19:11

RRV