【问题标题】:Where is the best place to set a custom Font as Default for the entire project or VisualTree?为整个项目或 VisualTree 设置自定义字体作为默认值的最佳位置在哪里?
【发布时间】:2014-05-12 20:41:08
【问题描述】:

我有一个需要使用自定义字体的 Windows Phone 7 应用/游戏。

示例:

在页面属性中设置:

FontFamily=".\Fonts\FontFileName.ttf#FontName"

或直接在TextBlockButton控件中。

当涉及UserControl 时,它会变得混乱,因为我需要设置UserControl.FontFamily 属性/属性。

是否有一个地方我可以设置一次,它适用于我的项目或 VisualTree 中的所有控件?

【问题讨论】:

标签: windows-phone-7 fonts windows-phone


【解决方案1】:

您可以使用 App.Resources 通过隐式样式设置所有控件的字体系列,

<Application.Resources>
    <ResourceDictionary>
        <Style TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Give your font name here" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="FontFamily" Value="Give your font name here" />
        </Style>
        --------
        --------
        Similarly set the style for all the controls you have used in your app
        --------
        --------
    </ResourceDictionary>
</Application.Resources>

为所有控件设置样式,无论您在应用中使用什么。

【讨论】:

    【解决方案2】:

    您应该使用 Blend 创建控件默认模板的副本:

    1. 右键单击要模板化的控件(例如:Button)并选择“编辑模板”->“编辑副本”。
    2. 在弹出窗口中,选择“全部应用”和“在应用程序中定义”,以便在每次出现此控件时默认应用此模板。
    3. 编辑模板以将FontFamily 的Setter 属性更改为所需的值。

    对需要自定义字体的每种类型的控件重复这些步骤。
    对于TextBlock 控件,您无法编辑模板,因此您必须使用样式(同样的想法)。

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      相关资源
      最近更新 更多