Xamarin FontAwesome无法从背后的代码工作 [英] Xamarin FontAwesome not working from code behind

查看:86
本文介绍了Xamarin FontAwesome无法从背后的代码工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我是否在这里错过了一些东西.

I am wondering if I am missing some thing here.

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

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> 

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

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;

推荐答案

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

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

Text = "\uf11a"

这篇关于Xamarin FontAwesome无法从背后的代码工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆