Silverlight 中的应用程序范围字体资源

发布于 2024-10-05 22:58:44 字数 706 浏览 4 评论 0 原文

我想看看是否可以在 Silverlight 控件中使用应用程序范围的字体,这些字体可以在 application.resources 中设置,然后在整个应用程序中使用。他们不需要指定字体的其他内容,例如粗体或斜体,只需指定名称即可。

大多数情况下,这适用于需要嵌入到应用程序中的自定义字体。例如,我正在寻找简单的东西(不是任何特定的控件或控件类型)...

<Setter x:Key="My First Font"
        Property="FontFamily"
        Value="VINERTIC.TTF#Viner Hand ITC" />

然后在任何给定的控件中我会键入...

<TextBlock FontFamily="{StaticResource "My First Font"}"
           x:Name="ApplicationTitle"
           Text="NEXT PAGE" Foreground="Red"/>

...或...

FontFamily="{Binding "My First Font"}"

或类似的东西。

我知道我所做的不起作用,但这就是我想要的效果。

我似乎找不到任何有关如何设置应用程序范围的字体系列的文档。有什么建议吗?

I'm looking to see if it is possible to use app-wide font in Silverlight controls that can be set in a application.resources and then used throughout the app. They don't need to specifify the other things about a font like bold or italic, just the name.

Mostly, this is for custom fonts that would require to be embedded into the app. For example, I'm looking for something simple like (not of any particular control or control type)...

<Setter x:Key="My First Font"
        Property="FontFamily"
        Value="VINERTIC.TTF#Viner Hand ITC" />

Then in any given control I would type...

<TextBlock FontFamily="{StaticResource "My First Font"}"
           x:Name="ApplicationTitle"
           Text="NEXT PAGE" Foreground="Red"/>

...or...

FontFamily="{Binding "My First Font"}"

or some such thing.

I know what I did doesn't work, but that is the desired effect.

I can't seem to find any documention on how to set app-wide font families. Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽手叙旧 2024-10-12 22:58:44

我认为这里有一些信息可以帮助您入门。

首先,我知道将字体嵌入共享库(例如:Silverlight 类库)的最简单方法是执行以下操作:

  1. 拥有一个类库,并了解其默认命名空间。对于本示例,类库的默认命名空间是Common.Windows
  2. 有字体。对于此示例,Action Man Bold.ttf,其中包含命名字体Action Man
  3. 将字体添加到共享库项目中的某个位置。例如,资源/字体文件夹。
  4. 将文件的构建操作设置为资源
  5. 构建项目。

执行这些步骤后,您可以在任何地方引用字体,包括样式,其语法类似于下面的文本块:

<TextBlock
 FontFamily="/Common.Windows;component/Assets/Fonts/Action Man Bold.ttf#Action Man" />

请注意,上面的 FontFamily 表达式在容器项目中工作并且在参考项目中。我没有使用字体的 zip 存档来测试这个过程,但我敢打赌,它仍然可以工作。

这应该可以帮助你开始。如果您有兴趣执行在样式中声明字体并在控件上使用该样式的额外(且有用)步骤,请考虑查看此资源:

http://www.silverlight.net/learn/quickstarts/control-styles/

Here is some information I think will get you started.

First off, the easiest way I know to embed a font in a shared library (ex: a Silverlight Class library), is to do the following:

  1. Have a class library, and know its default namespace. For this example, the default namespace of the class library is Common.Windows.
  2. Have a font. For this example, Action Man Bold.ttf, which contains the named font Action Man.
  3. Add the font somewhere in the shared library project. For example, the Assets/Fonts folder.
  4. Set the build action on the file to Resource.
  5. Build the project.

After following these steps, you can refer to the font wherever you please, including styles, with syntax similar to the text block below:

<TextBlock
 FontFamily="/Common.Windows;component/Assets/Fonts/Action Man Bold.ttf#Action Man" />

Note that the FontFamily expression above worked within the container project and within a referencing project. I didn't test this process with a zip archive of fonts, but I'd bet a fancy rock out of the garden that it would still work.

That should get you started. If you are interested in going the extra (and useful) step of declaring the font in a style, and using the style on your controls, consider taking a look at this resource:

http://www.silverlight.net/learn/quickstarts/control-styles/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文