Reputation: 1229
I need my WPF app to use a true-type font for a different language. I have the font located in a folder called 'fonts' inside the project. The font I'm using is available for free download here
Since the font is installed in my system i first tried
FontFamily="FMBasuru"
I've read the post here and tried doing (this is the exact markup I'm using including font name)
<Window.Resources>
<Style x:Key="SinhalaFont">
<Setter Property="TextElement.FontFamily" Value="fonts/#FMBasuru"/>
</Style>
</Window.Resources>
...
<TextBlock Style="{DynamicResource SinhalaFont}">r</TextBlock>
...
I made sure that I'm using the correct font name instead of the font filename. What could have I got wrong?
Upvotes: 25
Views: 43501
Reputation: 21873
Updated: Create a folder name Fonts and copy the font which you want and change the BuildAction to Resource
<Window.Resources>
<FontFamily x:Key="test" >/Fonts/#Pirulen</FontFamily>
</Window.Resources>
<Grid>
<TextBlock FontSize="25" HorizontalAlignment="Center"
FontFamily="{StaticResource test}">Kishore Kumar</TextBlock>
</Grid>
just refer this document
Upvotes: 24
Reputation: 3790
It's worked for me on Blend, I don't know about Visual Studio.
The font will be in the font list
From - Add a custom font to your application
Upvotes: 0
Reputation: 101
Without using style, you can simply add the font like this in the Window.xaml I included the font file inside the folder called "Fonts".
<Window
FontFamily ="./Fonts/#Arial"
>
And if you want to use another font for specific label or text block you can override it like this. You should insert the font file into the Fonts folder.
<TextBlock FontFamily = "./Fonts/#Tahoma" ></TextBlock>
Upvotes: 4
Reputation: 6460
I tried your code with this
<Setter Property="TextElement.FontFamily" Value="fonts/#Arial Narrow Bold"/>
and it worked successfully.
Have you marked your font as 'Resource' in the Build Action? If you haven't, do that now and try your code again.
Upvotes: 13