0

in my application in am using specific font and i am notice that in other machines that running my application this font is missing and in this case my application using different font (maybe default one ) so i wonder how to add this specific font to my application.

Edit

After try this solution:

Declate Style:

<Style x:Key="MyFont">
    <Setter Property="TextElement.FontFamily" Value="Resources/#BuxtonSketch.ttf" />
</Style>

BuxtonSketch.ttf locate in my resources folder, and inside my label:

<Label Content="Test"  FontSize="35" Style="{StaticResource MyFont}"/>

My label gets different font, did i miss something ?

i also try:

<Style x:Key="MyFont" TargetType="Label">
        <Setter Property="FontFamily" Value="Resources/#BuxtonSketch.ttf" />
    </Style>
Community
  • 1
  • 1
mark yer
  • 403
  • 6
  • 12
  • Take a look at http://stackoverflow.com/questions/6453640/how-to-include-external-font-in-wpf-application-without-installing-it – Nemanja Banda Jun 29 '15 at 11:57
  • Posted the answer with the new information that you provided, please let me know if it worked for you. You are using the wrong name for the font in your style, it should be the font name, not the file name. – Nemanja Banda Jun 29 '15 at 13:17

1 Answers1

0

Create the folder in your solution named Resources. Put the font file BuxtonSketch.ttf inside it and add it to the solution, set build action to Resource.

This is important, open the TTF file from Windows, and check the Font name value, this is the value that you need to use in your code. I guess it will be Buxton Sketch, so you write that value, without the extension.

Define the style in XAML:

<Window.Resources>
    <Style x:Key="MyFont">
        <Setter Property="TextElement.FontFamily" Value="Resources/#Buxton Sketch"/>
    </Style>
</Window.Resources>

And then apply the style to control:

<Label Content="Test" FontSize="35" Style="{StaticResource MyFont}"/>

EDIT: Corrected the font name

Nemanja Banda
  • 796
  • 2
  • 14
  • 23
  • i changed build action to Resource and copy your code and still nothing, i didn't understand how to check the font name value – mark yer Jun 29 '15 at 13:34
  • Double-click the TTF file from Windows explorer :) I downloaded the font myself, the name that you need to use is `Buxton Sketch`. Made the edit to the answer with the correct name. – Nemanja Banda Jun 29 '15 at 13:39
  • Paths are case sensitive, make sure your folder is named `Resources`, not `resources`. – Nemanja Banda Jun 29 '15 at 13:50
  • 1
    OK this works fine now, the problem was because i mover the build from resources to none, thanks a lot for your help – mark yer Jun 29 '15 at 13:52