How to install FontFamily in code

I am creating a WPF application where I need to use custom fonts. A font resource library has been created, as described here http://msdn.microsoft.com/en-us/library/ms753303.aspx . An example shows how to install a font family in XAML:

<Run FontFamily="/FontLibrary;Component/#Kootenay" FontSize="36">
  ABCDEFGHIJKLMNOPQRSTUVWXYZ
</Run>

How to install font family in code?

+5
source share
1 answer

Assign a name to your run, and then create a FontFamily with a URI constructor :

Xaml:

<Run x:Name="MyTextRun">ABC</Run>

Code behind:

MyTextRun.FontFamily = new FontFamily(new Uri("/FontLibrary;Component/#Kootenay", UriKind.RelativeOrAbsolute), "Kootenay");
MyTextRun.FontSize = 36;
+7
source

All Articles