I'm creating a WPF application where I need to use custom fonts. A created a font resource library as described here http://msdn.microsoft.com/en-us/library/ms753303.aspx. An example shows how to set a font family in XAML:
<Run FontFamily="/FontLibrary;Component/#Kootenay" FontSize="36">
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</Run>
How do I set a font family in the code?
Assign a Name to your run and then construct the FontFamily with the 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With