Monday, August 2, 2010

Wpf Custom Fonts


Include the *.ttf file into your WPF project as a Resource.

Reference it into a ResourceDictionary as follows:
    <FontFamily x:Key="WeirdFontFamily">/TestProject;Component/Fonts/#Weird</FontFamily>
    <FontFamily x:Key="WeirdBoldFontFamily">/TestProject;Component/Fonts/#Weird Bold</FontFamily>
I don't fully understand exactly what the # is doing, but suffice to say in this case it is followed by the font name not the file name.  The font name can be found by double clicking the TTF file which opens it in the WIndows Font Viewer.

Here's a usage example:

          FontFamily="{DynamicResource WeirdFontFamily}"

No comments:

Post a Comment