Silverlight中的应用程序范围字体资源 [英] App-wide Font resources in Silverlight

查看:141
本文介绍了Silverlight中的应用程序范围字体资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这主要是针对需要嵌入的自定义字体进入应用程序。例如,我正在寻找一些简单的东西(不是任何特定的控件或控件类型)...

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

然后在任何给定的控件中输入...

 < TextBlock FontFamily ={StaticResourceMy First Font}
x:Name =ApplicationTitle
Text =NEXT PAGEForeground = 红/>

...或...

 FontFamily ={BindingMy First Font}

或者一些这样的东西。



我知道我做了什么不行,但是这是所期望的效果。



我似乎无法找到关于如何设置应用程序范围的字体系列的任何文档。任何建议?

解决方案

这里有一些信息,我认为你会开始。


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


  1. 有一个类库,并知道它的默认命名空间。对于此示例,类库的默认名称空间是 Common.Windows
  2. 具有字体。在这个例子中, Action Man Bold.ttf 包含了命名字体

  3. 在共享库项目的某处添加字体。例如,资产/字体文件夹。

  4. 将文件的构建操作设置为资源


  5. $ b

    完成这些步骤后,您可以随时随地参考字体,包括样式,语法类似于下面的文本块:

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

    注意上面的 FontFamily 引用项目中的容器项目 。我没有用字体的zip存档来测试这个过程,但我敢打赌,一个花哨的岩石,它仍然会工作的花园。



    这应该得到你开始了。如果你有兴趣进行额外的(有用的)在风格中声明字体的步骤,并在你的控件上使用风格,可以考虑看看这个资源:



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


    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?

    解决方案

    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/

    这篇关于Silverlight中的应用程序范围字体资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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