如何在引用库中使用字体? [英] How to use font in the references library?

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

问题描述

我有dll它我的自定义控件。我需要使用来自应用程序的资源在dll中的字体。

I have dll It my custom control. I need to use font in dll from resources from the app.

我写的代码,但如果在PC上安装的字体工作。

I wrote code but it working if font installed on PC.


new Typeface(new FontFamily(new Uri(pack:// application:,,, Astro; Component / Fonts)

new Typeface(new FontFamily(new Uri("pack://application:,,,/Astro;Component/Fonts")

如何解决它的问题?我需要在PC上使用字体而不安装。

How to solve it problem? I need use font without install on PC.

推荐答案

p>如果将自定义控件封装在自己的程序集中,则不应该有对应用程序程序集的引用。将字体文件作为资源嵌入自定义控件项目中,或者定义一个独立的样式项目,然后从自定义控件和您的应用程序。

If you encapsulate the custom control inside it's own assembly, you shouldn't have a reference to the applications assembly from there. Embed the font files as resources inside your custom control project or define a distinct styling project which is then referenced from your custom control and your application as well.

然后,您可以定义和使用XAML字体系列作为资源,如下所示:XAML位于 Fonts.xaml 其位于与字体文件相同的文件夹中:

You can then define and use XAML font families as resources as shown below. The XAML is placed inside Fonts.xaml which is located in the same folder as the font files:

<FontFamily x:Key="ColaborateThin">./#Colaborate Thin</FontFamily>
<FontFamily x:Key="ColaborateRegular">./#Colaborate Regular</FontFamily>
<FontFamily x:Key="ColaborateBold">./#Colaborate Bold</FontFamily>
<FontFamily x:Key="DroidSansRegular">./#Droid Sans Regular</FontFamily>
<FontFamily x:Key="SegoeRegular">Segoe</FontFamily>

<Style x:Key="H1">
    <Setter Property="TextElement.FontFamily" Value="{StaticResource ColaborateThin}" />
    <Setter Property="TextElement.FontSize" Value="21px" />
    <Setter Property ="TextElement.Foreground" Value="{StaticResource PrimaryBrush}" />
</Style>

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

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