0

I am trying to use FontAwesome5 in a new Maui project. When I reference a glyph in the xaml literally, the icon renders just fine. However, when I attempt to have it backed by a Static class resource the glyph is not rendered and instead a string is rendered.

So this renders the icon correctly:

<Image Grid.Column="1" WidthRequest="40" HeightRequest="40" Margin="5,5,10,5" VerticalOptions="Center">
  <Image.Source>
    <FontImageSource FontFamily="{x:Static font:FontAwesome.Duotone}" Glyph="&#xf064;" />
  </Image.Source>
</Image>

But when moving it to a reference it does not:

<Image Grid.Column="1" WidthRequest="40" HeightRequest="40" Margin="5,5,10,5" VerticalOptions="Center">
  <Image.Source>
    <FontImageSource FontFamily="{x:Static font:FontAwesome.Duotone}" Glyph="{x:Static font:FontAwesome.Share}" />
  </Image.Source>
</Image>

Where FontAwesome.Share is in a static class containing:

[XamlCompilation(XamlCompilationOptions.Compile)]
public static class FontAwesome
{
  // ...
  public static string Share = "&#xf064;";
  // ...
}

Any ideas?

acupofjose
  • 2,159
  • 1
  • 22
  • 40
  • Have you tried urlencoding the & – Jason Nov 25 '22 at 22:24
  • Sure! "%26#xf064;" is rendered. So, no dice. – acupofjose Nov 25 '22 at 22:34
  • When you move the string to c#, you have to use c#'s syntax for representing a unicode character. Here is a StackOverflow Q&A that shows how to encode a unicode character in a c# string. [Unicode characters in string](https://stackoverflow.com/questions/19782670/unicode-characters-in-string). And here is the [relevant doc](https://learn.microsoft.com/en-us/dotnet/standard/base-types/character-encoding-introduction). – ToolmakerSteve Nov 25 '22 at 23:04

1 Answers1

0

Well. I'm not sure why, but the following works:

public static string Share = '\uf064'.ToString();

Hope that helps, future person!

acupofjose
  • 2,159
  • 1
  • 22
  • 40