The solution to the problem turned out to be in UWP, use the correct font family name.
Font Awesome 5 Free Solid
and not just "FontAwesome"
// FontFamily = @"/Assets/FontAwesome.otf#FontAwesome"; // incorrect font family name
FontFamily = @"/Assets/Fonts/FontAwesome.otf#Font Awesome 5 Free Solid";
For anyone interested in details:
I downloaded a font editor to check the internal font name and font family name. I made the mistake of code copying blog posts that used values from similar/older fonts. See image for actual content.
There are 2 types of solution I got to work:
1) A custom control in shared code /.netStandard Common project.
2) a custom renderer
Solution 1: Custom Label
public class FontAwesomeLabel: Xamarin.Forms.Label
{
public FontAwesomeLabel()
{
switch (Device.RuntimePlatform)
{
case Device.UWP:
// make sure the correct font family name is used. Check in a font editor
this.FontFamily = @"/Assets/Fonts/FontAwesome.otf#Font Awesome 5 Free Solid";
break;
}
}
}
Solution 2: Customer renderer on Standard Control
[assembly: ExportRenderer(typeof(Label), typeof(FontAwesomeLabelRenderer))]
namespace Oxando.UWP.CustomRenderers
{
public class FontAwesomeLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
// on UWP be sure use the Font Family name.
// get a font editor and check the name, if it doesnt match UWP wont load it
if (FontAwesomeUtil.CheckIsFA(e.NewElement.Text))
{
Control.FontFamily = new FontFamily("/Assets/Fonts/FontAwesome.otf#Font Awesome 5 Free Solid");
}
}
}
}
internal static class FontAwesomeUtil
{
public static bool CheckIsFA(string text)
{
if (text.Length == 0) return false;
if (text.Length > 1 || text[0] < 0xf000) return false;
return true;
}
}
}
Actual internal names as shown in Font editor
