Custom Font not working

jrahma 111 Reputation points
2021-03-04T21:05:06.6+00:00

Hi,

i am trying to use Font Awsome as the custom font in my app.

I added the icon and set it to EmbeddedResources and added:

[assembly: ExportFont("FontAwesomeRegular.otf", Alias = "FontRegular")]

but I am not getting the icon shown and it just shows the default question mark instead..

<Image>
<Image.Source>
    <FontImageSource Grid.Column="4" FontFamily="FontRegular" Color="Black" Glyph="&#xf004;"/>
</Image.Source>
</Image>

Kindly help..

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

7 answers

Sort by: Newest
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-09T03:13:59.037+00:00

    @StephenH

    Based on your sample , I made a simple test .

       <StackLayout>  
               <StackLayout BackgroundColor="Red" Orientation="Horizontal">  
         
                   <Image>  
                       <Image.Source>  
                           <FontImageSource FontFamily="FA5Solid900" Color="Black" Glyph="{x:Static FA:FontAwesomeIcons.Ankh}"/>  
                       </Image.Source>  
                   </Image>  
         
                   <Image>  
                       <Image.Source>  
                           <FontImageSource FontFamily="FA5Solid900" Color="Black" Glyph="{x:Static FA:FontAwesomeIcons.AppStore}"/>  
                       </Image.Source>  
                   </Image>  
         
                   <Image>  
                       <Image.Source>  
                           <FontImageSource FontFamily="FA5Solid900" Color="Black" Glyph="&#xf004;"/>  
                       </Image.Source>  
                   </Image>  
         
               </StackLayout>  
         
               <StackLayout  Orientation="Horizontal">  
         
                   <Label  FontFamily="FA5Solid900"  Text ="{x:Static FA:FontAwesomeIcons.Ankh}"  FontSize="30"/>  
         
                   <Label  FontFamily="FA5Solid900"   Text ="{x:Static FA:FontAwesomeIcons.AppStore}"  FontSize="30"/>  
         
                   <Label  FontFamily="FA5Solid900"   Text ="&#xf004;"  FontSize="30"/>  
         
               </StackLayout>  
           </StackLayout>  
    

    75510-capture.png

    I found

    • Not all the Unicode sting in FontAwesomeIcons works as expected. (Acorn ,AppStore not work but Ankh work)
    • The default color is light-gray not white, so we don't need to set color on it .
    • Unicode string or XML character escape does not work on ShellContent.Icon , it seems that it only supports existing image file .

  2. StephenH 86 Reputation points
    2021-03-08T23:53:12.917+00:00

    Iv'e had this problem for over a week and it got closed in my previous report with no solution other than to come here ......

    0 comments No comments

  3. StephenH 86 Reputation points
    2021-03-07T00:40:54.857+00:00

    I have uploaded a simple app using the ttf file and a known good working string constants file from here
    https://github.com/matthewrdev/fa2cs/blob/master/FontAwesomeIcons.cs

    https://github.com/stephenhauck/FontAwesomeCustomFont


  4. StephenH 86 Reputation points
    2021-03-07T00:21:13.197+00:00

    So the awesome guys at Mfractor suggested I try the ttf instead of the otf and that did not make a difference

    This works ...
    75048-image.png

    But this does not
    75086-image.png

    And again .. Mfractor knows what it is ....
    75087-image.png

    I even tried a different string constants file to no avail ...

    0 comments No comments

  5. StephenH 86 Reputation points
    2021-03-05T15:48:27.927+00:00

    I generated a class with constants using this ...
    https://andreinitescu.github.io/IconFont2Code/

    Also just noticed .. I am running Visual Studio 2019 on WIndows with MFractor and it decodes things properly while running and I put my pointer over it in the XAML ...

    74903-image.png

    0 comments No comments