Xamarin FontAwesome 无法从背后的代码中工作

Man*_*nsa 4 xaml xamarin font-awesome xamarin.forms

我想知道我是否在这里遗漏了一些东西。

在 iOS 的 xaml 中使用 FontAwesome 时,它​​的工作原理如下:

<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> 
Run Code Online (Sandbox Code Playgroud)

但是在页面后面的代码中执行此操作时,我没有得到图标而是它的 unicode &#xf075

这是我的代码背后的代码:

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;
Run Code Online (Sandbox Code Playgroud)

Dan*_*l P 8

在 C# 代码中使用时,您必须像这样使用它:

Text = "\uf11a"