My biggest struggle in winiot/UWP so far... but here goes...
A few considerations for somebody else who's pulling his/her hair out.
First of all, it is possible. But many websites tell you a different story which overcomplicate an already overcomplicated feature imho.
The steps that you need to fulfil to visualize your font on your iot device:
Add the fonts to your project
The obvious first step that most websites will tell you. A few remarks though.
- It does NOT matter WHERE you store the fonts. They can reside in /Assets, /Fonts, /Assets/Fonts, /Resources or whatever you prefer.
- You do NOT have to bother with
copy to output
. It doesn't matter how you define it.
- You do need to leave the build action to
Content
. Which is the default, so you don't have to bother with that either.
Refer the font family name
It can be horrible to figure out the correct font name. The convention is as follows [fontfamily file path]#[font family name].
An example would be:
Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto
Or in complete xaml:
<TextBlock FontFamily="Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
It does NOT matter whether you refer the path with the msappx syntax, all following definitions will work :
<TextBlock FontFamily="Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
<TextBlock FontFamily="/Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
<TextBlock FontFamily="ms-appx:///Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
The font name
Then the big one, the font name. Important to know, is that the font style should be REMOVED from the font name. Thus for example
- File 'Delphi-Soleto_Blk.ttf' with font name Delphi-Soleto Light becomes Delphi-Soleto
- File 'Delphi-Soleto_Blk.ttf' with font name Delphi-Soleto Black becomes Delphi-Soleto
- File 'Delphi-Soleto_A_Blk.ttf' with font name Delphi-Soleto App Black becomes Delphi-Soleto App
In order to save you hours from guessing as I started out with, there is a tool that can help you out big time here. Be careful with the windows font viewer, as it might not show you what you need to see. Download the free dp4 font viewer instead.
If you open dp4 font viewer and locate the folder that holds your fonts you will see the correct font name. Note the font family name in the screenshot below.
Verify text in desired font
Then last but not least, some websites claim that xaml designer will instantly show the text in the font, which would be easy for testing. It does NOT do that on my side. What did help me in the end, is deploy my app on my target (in my case a RPI) and change the XAML while the app is running in the debugger. These changes do reflect instantly in your running app.
Finally, I could look at my screen and see my fonts visualized
I hope this will somebody out there! Special thanks to Breeze Liu who took the time to help me out!