带有自定义字体的标签和带有绑定的文本不起作用 [英] Label with custom font and text with binding doesn't work

查看:27
本文介绍了带有自定义字体的标签和带有绑定的文本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Label,其中 Font 设置为图标字体(font awesome),其 Text 绑定如下:

I have a Label with Font set to an icons font (font awesome) which has the Text bound like this:

<Label Text='{Binding Icon}'>
  <Label.FontFamily>
    <OnPlatform x:TypeArguments="x:String">
        <OnPlatform.iOS></OnPlatform.iOS>
        <OnPlatform.Android>icons.ttf#Icons</OnPlatform.Android>
    </OnPlatform>
 </Label.FontFamily>
</Label>

它不呈现图标,而是呈现 Unicode 值 &#xf032;.

it doesn't render the icon, it renders the Unicode value &#xf032; instead.

如果我设置没有绑定的文本,它会起作用,如下所示:

It works if I set the text without binding, like this:

<Label Text='&#xf032;'>

我怀疑在设置文本和字体之间存在某种竞争条件.

I suspect there's some kind of race condition between setting the text and the font.

我需要绑定,但我不知道任何解决方法.

I need the binding, but I don't know any workarounds.

推荐答案

从绑定中返回 \uf032 的转义序列而不是 &#xf032;

Return the escape sequence of \uf032 from your binding instead of instead of &#xf032;

这篇关于带有自定义字体的标签和带有绑定的文本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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