How to change font family for Xamarin Shell FlyoutItem

2k views Asked by At

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.

2

There are 2 answers

0
Cfun On BEST ANSWER

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?

1
Wendy Zang - MSFT On

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