I have an assembly that defines styles and some controls for a WPF application. In this assembly, I have a ResourceDictionary that specifies a 'default font' for use by the other controls and styles in the assembly.
<FontFamily x:Key="DefaultFontFamily">Segoe UI</FontFamily>
<sys:Double x:Key="DefaultFontSize">15</sys:Double>
What I would like to do is change the DefaultFontFamily to a custom font that is linked (not embedded) with the assembly.
I have created a 'Resources' folder in the project and copied the custom font there. I've set the font's 'Build Action' to 'Content' and 'Copy to Output Directory' to 'Copy if newer'.
The project is part of a solution containing another project that uses the styles in the assembly, so when the solution is built, the fonts are copied over as expected. I can't seem to specify the correct folder to reference the fonts though.
What works:
<FontFamily x:Key="DefaultFontFamily">C:\code\Solution\Project\bin\Debug\Resources\Lobster-Regular.ttf#Lobster</FontFamily>
<FontFamily x:Key="DefaultFontFamily">file:///c:/code/Solution/Project/bin/Debug/Resources/Lobster-Regular.ttf#Lobster</FontFamily>
Here 'Project' is the name of the startup (executable) project that references the styles assembly.
What does not work:
<FontFamily x:Key="DefaultFontFamily">\Resources\Lobster-Regular.ttf#Lobster</FontFamily>
<FontFamily x:Key="DefaultFontFamily">.\Resources\Lobster-Regular.ttf#Lobster</FontFamily>
<FontFamily x:Key="DefaultFontFamily">/Resources/#Lobster</FontFamily>
<FontFamily x:Key="DefaultFontFamily">./Resources/#Lobster</FontFamily>
I've also tried setting the content of the font to both 'Resource' and 'Embedded Resource' and tried this:
<FontFamily x:Key="DefaultFontFamily">pack://application:,,,/Resources/Lobster.ttf#Lobster</FontFamily>
This didn't work either. The documentation says I should be able to use:
A string specifying a folder containing the font, along with a font family name. The folder and font family name are delimited by a # character. The folder reference may be absolute, or relative. For example, "Custom Fonts\#My Custom Font".
What am I doing wrong?