0

So after quick search i found this solution:

I have inside my Resources folder fond called Abstract.

<Window.Resources>
   <Style x:Key="Abstract">
       <Setter Property="Label.FontFamily" Value="Resources/#Abstract" />
   </Style>
</Window.Resources>

And my Label:

<Label Name="lblValue"
       Content="Value"                                
       Style="{DynamicResource Abstract}"
       FontSize="14"/>

And nothing happening, i just cannot see the font i want.

user979033
  • 5,430
  • 7
  • 32
  • 50

1 Answers1

1

There's a memory leak you need to be aware of.

Any font reference which uses a relative path will cause a memory leak. The way to do this is to use an absolute path. And yes, that is a nuisance.

See this: WPF TextBlock memory leak when using Font

I've recently been working on something which uses fancy fonts and investigated the issue. It's still there with .net 4.7. I wouldn't use a temporary folder, deliver your ttf to the same folder as your exe or into local appdata if you have several apps which will use the same ttf.

My plan, when I get round to this specific aspect of our app, is to write a custom markup extension which will allow me to pass a short name and go find the absolute path on the user's machine. I'll be using appdata.

Your immediate problem is because you're not using a relative path. Put a / in front of your path there.

Value="/Resources/#Abstract"

But you will then have a memory leak.

Andy
  • 11,864
  • 2
  • 17
  • 20
  • Finally this work using this link: https://stackoverflow.com/questions/6453640/how-to-include-external-font-in-wpf-application-without-installing-it/39912794#39912794 with the first way - Package with Application, this also lead to memory leak ? – user979033 Mar 29 '18 at 09:26
  • Yes. The only way to avoid it is to have an absolute path. Unless the path you use starts something like "C:\..." then it will cause a memory leak. – Andy Mar 29 '18 at 09:33
  • What exactly is absolute path ? – user979033 Mar 29 '18 at 10:28
  • A path which starts "C:\" is absolute. If you don't have a drive letter on the front of your path then it isn't absolute. – Andy Mar 29 '18 at 10:49
  • All the paths I see in that thread you linked are relative. EG new FontFamily(new Uri("pack://application:,,,/ is relative to your application. You can't put them into file manager and find the file. – Andy Mar 29 '18 at 10:56