Xamarin FontAwesome not working from code behind

大兔子大兔子 提交于 2019-12-11 07:43:11

问题


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;

回答1:


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

Text = "\uf11a"



来源:https://stackoverflow.com/questions/52274361/xamarin-fontawesome-not-working-from-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!