如何在不安装的情况下在 WPF 应用程序中包含外部字体 [英] How to include external font in WPF application without installing it
本文介绍了如何在不安装的情况下在 WPF 应用程序中包含外部字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不安装的情况下在 WPF 应用程序中包含外部字体
How to include external font in WPF application without installing it
我试过这个代码
System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
privateFonts.AddFontFile("C:\Documents and Settings\somefont.ttf");
System.Drawing.Font font = new Font(privateFonts.Families[0], 12);
this.label1.Font = font;
它在 Windows 窗体应用程序中正常工作,但在 WPF 中无法正常工作.
It working correctly in Windows Form Application but not in WPF.
推荐答案
我使用这样的 XAML 代码:
I use such XAML code:
<Style x:Key="Hatten">
<Setter Property="TextElement.FontFamily" Value="Resources/#HATTEN" />
</Style>
#HATTEN - 参考资源中的 hatten.tft.
#HATTEN - reference to hatten.tft in Resources.
使用样式:
<TextBlock x:Name="lblTitle" Style="{DynamicResource Hatten}" FontSize="72"></TextBlock>
这篇关于如何在不安装的情况下在 WPF 应用程序中包含外部字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文