Don Box
Don Box

Reputation: 3336

Label with custom font and text with binding doesn't work

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>

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.

Upvotes: 5

Views: 1238

Answers (2)

MAXE
MAXE

Reputation: 5122

SushiHangover's works in my case but if you're using Font Awesome Material Design Icons (referenced in my XAML as materialdesignicons.ttf#Material Design Icons) or any Unicode character that exceeds 0xFFFF, you need to use a syntax like this:

"\U000F09D7"

Upvotes: 0

SushiHangover
SushiHangover

Reputation: 74094

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

Upvotes: 9

Related Questions