在WPF中使用自定义字体 [英] Using a custom font in WPF

查看:425
本文介绍了在WPF中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的WPF应用程序将真型字体用于其他语言。我将字体放在项目内名为 fonts的文件夹中。我正在使用的字体可以免费下载此处

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"

我已经阅读了帖子< a href = https://stackoverflow.com/questions/358501/wpf-add-custom-font>此处并尝试执行操作(这是我正在使用的确切标记,包括字体名称)

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?

推荐答案

我尝试过使用此代码

  <Setter Property="TextElement.FontFamily" Value="fonts/#Arial Narrow Bold"/>

,它成功运行。

您是否在Build Action中将字体标记为 Resource?如果还没有,请立即执行,然后重试您的代码。

Have you marked your font as 'Resource' in the Build Action? If you haven't, do that now and try your code again.

这篇关于在WPF中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆