Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom font in WPF

Tags:

.net

wpf

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?

like image 670
Prabath Yapa Avatar asked Sep 22 '10 01:09

Prabath Yapa


People also ask

How to change font in WPF?

The FontSize, FontFamily, FontWeight, FontStyle, and FontStretch properties are used to set the font size, family, weight, style and stretch to the text of a TextBox. The code snippet in Listing 6 sets the font properties of a TextBox.

What is WPF default font?

In WPF, the default font family for text displayed on controls (like Label and Button) is Segoe UI, with a default size of 12.0 device-independent units.


1 Answers

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

like image 82
Kishore Kumar Avatar answered Sep 29 '22 00:09

Kishore Kumar