This actually is possible! Instead of specifying FontFamily="/Fonts/MyFont/MyFont-Regular.ttf#My Font"
you should rather specify only the folder with your font files and the name of the font:
FontFamily="/Fonts/MyFont/#My Font"
WPF then inspects all font files in that directory and loads them into one FontFamily
if the font name matches the name specified after the #
.
This way you can easily define one FontFamily
in your resources and use its styles by specifying the properties FontWeight
and FontStyle
:
<FontFamily x:Key="MyFont">/Fonts/MyFont/#My Font</FontFamily>
<!-- somewhere else: -->
<TextBlock
Text="Hello World"
FontFamily="{StaticResource MyFont}"
FontWeight="Bold"/>
This will automatically use your TTF files from that folder.