How to use my downloaded fonts in WinUI 3?

Luyen Do 25 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.
794 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 85,806 Reputation points
    2023-04-04T11:46:03.7633333+00:00

    You don't need to install fonts.

    There is a bug in your code : remove the "/" in FontFamily name.

    Test : User's image

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 45,096 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.