如何:设置版式属性

更新:2007 年 11 月

Windows Presentation Foundation (WPF) 包括对一组复杂版式属性的支持。这些属性可以在代码的 TextRun 级别使用,也可以在可扩展应用程序标记语言 (XAML) 中使用。

示例

下面的代码示例演示如何在 XAML 中使用下标、上标和其他版式 Variants。Variant 功能是某些类型的版式项,其中使用备用标志符号形状来表示窗体。请注意,此 Variant 功能仅限于 Run 元素中包含的文本。

<FlowDocument FontFamily="Palatino Linotype" FontSize="24">
  <Paragraph>
    This is an <Run Typography.Variants="Ordinal">ordinal</Run><LineBreak/>
    This is a <Run Typography.Variants="Superscript">superscript</Run><LineBreak/>
    This is a <Run Typography.Variants="Subscript">subscript</Run><LineBreak/>
    This is an <Run Typography.Variants="Inferior">inferior</Run><LineBreak/>
  </Paragraph>
</FlowDocument>

下面的代码示例演示如何在 XAML 中使用版式 Capitals。请注意,此 Variant 功能适用于 Paragraph 元素中包含的所有文本。

<FlowDocument FontFamily="Palatino Linotype" FontSize="24">
  <Paragraph Typography.Capitals="SmallCaps">
    This example shows the use of the Capitals property
    of the Typography object. The entirety of this paragraph
    is displayed in small capitals letters,
    except for the first letter of a sentence,
    and where an uppercase letter is used. In these cases,
    a large capital letter is used.
  </Paragraph>
</FlowDocument>

下面的代码示例演示如何在 XAML 中使用版式 CapitalsNumeralStyle 功能。请注意,这两个版式属性适用于整个段落。

<FlowDocument FontFamily="Palatino Linotype" FontSize="24">
    <Paragraph Typography.Capitals="SmallCaps" Typography.NumeralStyle="OldStyle">
      Welcome to C#! . . . 14<LineBreak/>
      Working with Variables, Operators, and Expressions . . . 29<LineBreak/>
      Writing Methods and Applying Scope . . . 45
    </Paragraph>
</FlowDocument>

请参见

概念

OpenType 字体功能