Using a custom font in WPF

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.


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>

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

WPF - Add Custom Font

Tags:

.Net

Wpf