0

Is there any way to change the font family of contents inside FlyoutItem in Xamarin Forms Shell?

I've already added custom .ttf fonts in shared project as embedded resource and also registered the font file with the assembly using the file, AssemblyInfo.cs.

Any help would be appreciated.

Eoin
  • 147
  • 1
  • 2
  • 16

2 Answers2

1

For Shell Flyout content (Flyout Items + menu items) you can use a style with FlyoutItemLabelStyle class:

<Style ApplyToDerivedTypes="True" Class="FlyoutItemLabelStyle" TargetType="Label">
     <Setter Property="FontFamily" Value="YourFontExportName"/>
</Style>

From docs Style FlyoutItem and MenuItem objects.

Related questions

How to use Font Awesome icons in project as an icon of ImageButton

Using Material Design Icons with Xamarin Forms - What Am I Missing?

Cfun
  • 8,442
  • 4
  • 30
  • 62
0

Like Cfun said, you could set the Shell Flyout items font with the FlyoutItemLabelStyle.

  1. Add the font to your Xamarin.Forms shared project as an embedded resource (Build Action: EmbeddedResource).

  2. Register the font file with the assembly, in a file such as AssemblyInfo.cs, using the ExportFont attribute. An optional alias can also be specified.

    AssemblyInfo.cs:

    [assembly: ExportFont("Trashtalk.ttf", Alias = "Trashtalk")]
    
  3. Add this Font in your style.

    <Style Class="FlyoutItemLabelStyle" TargetType="Label">
             <Setter Property="FontFamily" Value="Trashtalk" />
         </Style>
    

Screenshot:

enter image description here

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17
  • 1
    Could you explain how this answer is different than mine? The OP mentionned that he already added the font file, set it as embedded respource and exported it using assembly. So the OP already done the previous steps (covered by some answers around SO) and only asking about styling. – Cfun Mar 10 '21 at 10:34