如何在代码中设置FontFamily [英] How to set FontFamily in code

查看:29
本文介绍了如何在代码中设置FontFamily的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个需要使用自定义字体的 WPF 应用程序.A 创建了一个字体资源库,如下所述 http://msdn.microsoft.com/en-us/library/ms753303.aspx.一个示例展示了如何在 XAML 中设置字体系列:

I'm creating a WPF application where I need to use custom fonts. A created a font resource library as described here http://msdn.microsoft.com/en-us/library/ms753303.aspx. An example shows how to set a font family in XAML:

<Run FontFamily="/FontLibrary;Component/#Kootenay" FontSize="36">
  ABCDEFGHIJKLMNOPQRSTUVWXYZ
</Run>

如何在代码中设置字体系列?

How do I set a font family in the code?

推荐答案

为您的运行分配一个名称,然后使用 URI 构造函数:

Assign a Name to your run and then construct the FontFamily with the URI constructor:

XML:

<Run x:Name="MyTextRun">ABC</Run>

背后的代码:

MyTextRun.FontFamily = new FontFamily(new Uri("/FontLibrary;Component/#Kootenay", UriKind.RelativeOrAbsolute), "Kootenay");
MyTextRun.FontSize = 36;

这篇关于如何在代码中设置FontFamily的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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