How to use my downloaded fonts in WinUI 3?

Luyen Do 20 Reputation points
2023-04-03T08:02:21.6933333+00:00

In my WinUI 3 app, I try to declare and apply my downloaded fonts but it doesn't work.

Note: If I manually install the font on my computer, it works well. I wonder if the font installation is a must-have step in WinUI 3?

Steps that I have done

  • Add fonts .tff file to myapp/Assets/Fonts
    User's image
  • Add resource dictionary:
   <ResourceDictionary>
       <FontFamily x:Key="DancingScriptBold">/Assets/Fonts/DancingScript-Bold.ttf/#Dancing Script</FontFamily>
   </ResourceDictionary>
  • Apply to my custom textblock style:
                       <Style x:Key="Body1" TargetType="TextBlock">
                           <Setter Property="FontSize" Value="14" />
                           <Setter Property="FontFamily" Value="{StaticResource DancingScriptBold}" />
                       </Style>
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
745 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 42,761 Reputation points
    2023-04-03T08:16:46.8366667+00:00

    I wonder if the font installation is a must-have step

    If you want to use a font in any app, also like Ofiice/Word, then installing the font on the machine is always a must-have.