0

So i try to add external font int my application using this post

Steps:

Add a /Fonts folder to your solution. Add the True Type Fonts (*.ttf) files to that folder Include the files to the project Select the fonts and add them to the solution Set BuildAction: Resource and Copy To Output Directory: Do not copy. Your .csproj file should now should have a section like this one:

 <ItemGroup>
  <Resource Include="Fonts\NotoSans-Bold.ttf" />
  <Resource Include="Fonts\NotoSans-BoldItalic.ttf" />
  <Resource Include="Fonts\NotoSans-Italic.ttf" />
  <Resource Include="Fonts\NotoSans-Regular.ttf" />
  <Resource Include="Fonts\NotoSansSymbols-Regular.ttf" />
</ItemGroup>

In App.xaml add Resources. It should look like in the following code sample. Note that the URI doesn't contain the filename when packing with the application.

<Applicaton ...>
<Application.Resources>
    <FontFamily x:Key="NotoSans">pack://application:,,,/Fonts/#Noto Sans</FontFamily>
    <FontFamily x:Key="NotoSansSymbols">pack://application:,,,/Fonts/#Noto Sans Symbols</FontFamily>
</Application.Resources>
</Application>

Apply your Fonts like this:

<TextBlock x:Name="myTextBlock" Text="foobar" FontFamily="{StaticResource NotoSans}" 
           FontSize="10.0" FontStyle="Normal" FontWeight="Regular" />

So i download several fonts but this works only for some of them.

Any ideas?

falukky
  • 1,099
  • 2
  • 14
  • 34
  • how does "fail/work" show? files not included when published, fonts not used although selected in a control, runtime exception, ...? – Cee McSharpface Jul 19 '18 at 17:39
  • I follow all the steps above, i just see the default font, the other font that work so i can see this font – falukky Jul 19 '18 at 17:45

0 Answers0