I've searched nearly whole Internet to find an answer for my question, but untortunately didn't find it. I'm working on the WPF .Net Core 3.1 application, where I want to use custom font. Currently I'm working in Visual Studio 2019 Community 16.5.5
I've got plenty .ttf
files located in project's /Fonts
folder.
Their properties are set correct: Build Action: Resource
and Copy to Output Directory: Do not copy
.
Then I've created /Styles/Fonts.xaml
file and put this code inside:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GenoSoft.Word">
<FontFamily x:Key="LatoThin">pack://application;,,,/Fonts/#Lato Thin</FontFamily>
</ResourceDictionary>
In App.xaml
I've added Merged Dictionary:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Fonts.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
In MainWindow.xaml
I'm using this font as following:
<TextBlock Text="Welcome, Friend!" FontFamily="{StaticResource LatoThin}"/>
But designer doesn't change the design-time appearance of the TextBlock. When I build and run the application the font is displayed correctly in runtime, but not in designer.
- Doing exactly same thing in .Net Framework 4.7.2 makes designer display this font,
- Installing this font in my
C:\Windows\Fonts
folder doesn't make StaticResource font to appear in designer, but settingFontFamily="Lato Thin"
works well, but that's not a way to go, - Using font as
Content
also doesn't work
I would be grateful for any advices.