using custom font in xaml

2019-07-05 05:32发布

问题:

I need to use custom font in xaml (c#). The font is not installed on the computer.

If the font is in the application installed folder,then i can use it even if it is not installed (/Fonts/New12.ttf#New12)

My problem is that the custom font is been created on the local computer and can't be in the installed folder.

The problem is that i can't copy the ttf file to the application installed folder , and i don't know how to use custom font that is not on the application installed folder

Is anyone have an idea ?

回答1:

Add the font to your project, change its Build Action to Content. Then just reference it inline or as part of a Style or BasedOn value like;

<TextBlock FontFamily="/Fonts/New12.ttf#New12" Text="Check out my awesome font!" />

That should do it for you.



回答2:

I found the solution,

For the FontFamily value you can write

"ms-appdata:///local/MyFont.ttf#FontName"

(where local is ApplicationData::Current->LocalFolder)