Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

.net - Using a custom font in 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...