Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin FontAwesome not working from code behind

I am wondering if I am missing some thing here.

When using FontAwesome in xaml for iOS it works just fine like this:

<Button Text="&#xf075;" HeightRequest="100" BackgroundColor="DarkRed" TextColor="White" FontSize="36">
    <Button.FontFamily>
        <OnPlatform x:TypeArguments="x:String" Android="fa-regular-400.ttf#Font Awesome 5 Free Regular" iOS="Font Awesome 5 Free" WinPhone="Assets/fa-regular-400.ttf#Font Awesome 5 Free" />
    </Button.FontFamily>
</Button> 

But when doing this in the code behind for the page I do not get the icon but its unicode &#xf075;

Here is my code behind code:

var newBtn = new Button()
{

    Text = "&#xf11a;",
    HeightRequest = 100,
    BackgroundColor = Color.DarkRed,
    TextColor = Color.White,
    FontSize = 36

};

newBtn.FontFamily = Device.RuntimePlatform == Device.iOS ? "Font Awesome 5 Free" : null;
like image 535
Mansa Avatar asked Jan 27 '23 11:01

Mansa


1 Answers

When using from within C# code, you have to use it like this:

Text = "\uf11a"

like image 89
Daniel P Avatar answered Feb 04 '23 21:02

Daniel P