How to embed a font file into your Windows 8 Store applications in XAML

Posted: (EET/GMT+2)

 

Happy December! Quick tip for today regarding Windows 8 Store application development with XAML. If you want your application to use custom fonts, you can use Visual Studio 2012 or Blend 5 to select the font you want, and the font is nicely displayed in the designers. However, if you would deploy your app or run it in the Windows 8 simulator, the custom font doesn't display.

What you need to do is copy the font file (usually, the .ttf file) to your project, set the build action to Content, and then reference both the font file and the font inside that file using the FontFamily tag as follows:

<TextBlock FontFamily="Assets/OldEnglish.ttf#Old English Text MT" … />

That is, the syntax is: "folder/filename.ttf#fontname". This can be used with almost any XAML control that can display text.

Hope this helps!