【问题标题】:Xamarin FontAwesome not working from code behindXamarin FontAwesome 不能从后面的代码中工作
【发布时间】:2018-09-11 10:59:02
【问题描述】:

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

当在 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> 

但是在页面后面的代码中执行此操作时,我没有得到图标,而是得到它的 unicode &amp;#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;

【问题讨论】:

  • 试试这个Text = ((char)0xf11a).ToString();
  • 完美,就像 Daniel P 的回答一样。谢谢 :-)
  • 问题...如果您有 FA-Pro 的许可证,我该如何使用它?
  • @Mansa- 我从未使用过 FA 许可证。但是,您可以去 FA 支持部门并连同您的查询一起发送邮件给他们。或者在此处或在 xamarin 论坛上提出相同的问题,您可能会得到答案。

标签: xaml xamarin xamarin.forms font-awesome


【解决方案1】:

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

Text = "\uf11a"

【讨论】:

  • 如果我将值直接传递给元素,则此方法有效,但如果将值存储到变量中,则它不起作用。我该如何解决这个问题?
  • @AmirImam 我遇到了同样的问题。声明属性 static 而不是 const 解决了这个问题
猜你喜欢
  • 2020-07-30
  • 2017-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-10
  • 2018-10-15
  • 1970-01-01
  • 2020-08-16
相关资源
最近更新 更多