In this post i will show how to embed custom fonts into your app. You can find some free fonts here.
Step 1. – Make the font file usable
Fist we have to do is to add our fonts to the project – simply copy font file to desired folder in your project, e.g. “Fonts” folder. On the properties of the font file we have to set few properties:
- Build action: Content,
- Copy to Output Directory: Copy if newer
This is critical, if you do not set this two properties you wont be able to actually use font file.
Step 2. – Actually use the font file
To use the font file we have to reference the file, in xaml, like this:
<TextBlock FontSize="35" FontFamily="Fonts/BOMB.ttf#RMbomb" Text="SAMPLE TEXT" VerticalAlignment="Center" />
Pay attention to the FontFamily property of the TextBlock. First set the path to the font file, in my case: Fonts/BOMB.ttf, then add: “#”, and at the end add font name: RMbomb. To see what’s your font name just open font file in Windows Font Viewer, and font name will be in the title bar.
Here is how that all looks in actual Windows Phone application.
Download source here.