Xamarin FontAwesome不能从代码背后工作

问题描述 投票:1回答:1

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

在xaml for iOS中使用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> 

但是当在页面后面的代码中执行此操作时,我没有获得图标,但是它的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;
xaml xamarin xamarin.forms font-awesome
1个回答
4
投票

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

Text = "\uf11a"

© www.soinside.com 2019 - 2024. All rights reserved.