流文档概述

来源:百度文库 编辑:神马文学网 时间:2024/05/25 08:47:59
Windows Presentation Foundation
流文档概述
流文档旨在优化查看和可读性。流文档根据运行时变量(例如,窗口大小、设备分辨率和可选的用户首选项)来动态调整和重新排列文档内容,而不是设置为一个预定义的布局。此外,流文档还提供一些高级文档功能,例如,分页和分栏。本主题概述了流文档及其创建方式。
本主题包括下列各节。
什么是流文档?
流文档类型
创建流内容
与流相关的类
内容架构
自定义文本
相关主题
 什么是流文档?
流文档旨在根据窗口大小、设备分辨率和其他环境变量来“调整内容的流动”。此外,流文档还具有很多内置功能,包括搜索、能够优化可读性的查看模式以及更改字体大小和外观的功能。当文档首先看重易于阅读时,最适合使用流文档。相反,固定文档旨在提供静态表示形式。当源内容的高保真至关重要时,固定文档非常有用。有关不同类型文档的更多信息,请参见Windows Presentation Foundation 中的文档。
下图演示在多个不同大小的窗口中查看同一个示例流文档的情况。随着显示区域的变化,内容将调整流动,从而最好地利用可用空间。

如上图所示,流内容可以包括很多个组成部分,包括段落、列表、图像等等。这些组成部分对应于标记中的元素和程序代码中的对象。稍后,我们将在本概述的“与流相关的类”一节中详细介绍这些类。现在,我们提供一个简单的代码示例,其中创建了一个流文档,该文档由一个包含一些粗体文本的段落和一个列表组成。
复制代码
Some bold text in the paragraph.Some text that is not bold.ListItem 1ListItem 2ListItem 3
C#
复制代码
using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class SimpleFlowExample : Page{public SimpleFlowExample(){Paragraph myParagraph = new Paragraph();// Add some Bold text to the paragraphmyParagraph.Inlines.Add(new Bold(new Run("Some bold text in the paragraph.")));// Add some plain text to the paragraphmyParagraph.Inlines.Add(new Run(" Some text that is not bold."));// Create a List and populate with three list items.List myList = new List();// First create paragraphs to go into the list item.Paragraph paragraphListItem1 = new Paragraph(new Run("ListItem 1"));Paragraph paragraphListItem2 = new Paragraph(new Run("ListItem 2"));Paragraph paragraphListItem3 = new Paragraph(new Run("ListItem 3"));// Add ListItems with paragraphs in them.myList.ListItems.Add(new ListItem(paragraphListItem1));myList.ListItems.Add(new ListItem(paragraphListItem2));myList.ListItems.Add(new ListItem(paragraphListItem3));// Create a FlowDocument with the paragraph and list.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(myParagraph);myFlowDocument.Blocks.Add(myList);// Add the FlowDocument to a FlowDocumentReader ControlFlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();myFlowDocumentReader.Document = myFlowDocument;this.Content = myFlowDocumentReader;}}}
下图显示了此代码段。

在此示例中,FlowDocumentReader 控件用于承载流内容。有关流内容宿主控件的更多信息,请参见流文档类型。Paragraph、List、ListItem 和Bold 元素用于根据它们在标记中的顺序来控制内容格式。例如,Bold 元素只涵盖该段落中的一部分文本,因此,只有这一部分文本是粗体。如果您使用过 HTML,那么这对于您来说应该很熟悉。
正如上图中突出显示的那样,流文档中有多个内置功能:
搜索:使用户可以对整个文档执行全文搜索。
查看模式:用户可以选择他们喜欢的查看模式,包括单页(一次一页)查看模式、一次两页(书本阅读格式)查看模式和连续滚动(无界限)查看模式。 有关这些查看模式的更多信息,请参见FlowDocumentReaderViewingMode。
页面导航控件:如果文档的查看模式使用页面,则页面导航控件包括一个用于跳转到下一页(下箭头)或上一页(上箭头)的按钮,以及显示当前页码和总页数的指示器。也可以使用键盘上的箭头键来实现翻页的操作。
缩放:缩放控件使用户可以通过单击加号或减号按钮来相应地增大或减小缩放级别。缩放控件还包含一个用于调整缩放级别的滑块。有关更多信息,请参见Zoom(缩放)。
这些功能可以根据用于承载流内容的控件进行修改。下一节将介绍各种控件。
 流文档类型
流文档内容的显示和外观依赖于用于承载流内容的对象。有四个控件可以为查看流内容提供支持:FlowDocumentReader、FlowDocumentPageViewer、RichTextBox 和FlowDocumentScrollViewer。下面简要介绍了这些控件。
注意:需要使用FlowDocument 来直接承载流内容,因此所有这些查看控件都使用一个FlowDocument 来启用流内容承载。
FlowDocumentReader
FlowDocumentReader 包含一些功能,使用户能够动态地在各种查看模式之间进行选择,这些查看模式包括单页(一次一页)查看模式、一次两页(书本阅读格式)查看模式和连续滚动(无界限)查看模式。有关这些查看模式的更多信息,请参见FlowDocumentReaderViewingMode。如果您不需要在不同查看模式之间动态切换的功能,则可以使用FlowDocumentPageViewer 和FlowDocumentScrollViewer,它们提供了固定使用特定查看模式的轻量级流内容查看器。
FlowDocumentPageViewer 和 FlowDocumentScrollViewer
FlowDocumentPageViewer 以一次一页的查看模式显示内容,而FlowDocumentScrollViewer 以连续滚动模式显示内容。FlowDocumentPageViewer 和FlowDocumentScrollViewer 都固定使用特定查看模式。与FlowDocumentReader 相比,后者包含一些功能,使用户能够动态地在各种查看模式(由FlowDocumentReaderViewingMode 枚举提供)之间进行选择,但代价是需要消耗比FlowDocumentPageViewer 或FlowDocumentScrollViewer 更多的资源。
默认情况下,总是显示垂直滚动条,而水平滚动条则在需要时显示。FlowDocumentScrollViewer 的默认 UI 不包括工具栏;不过,可以使用IsToolBarVisible 属性来启用内置工具栏。
RichTextBox
若要允许用户编辑流内容,请使用RichTextBox。例如,如果您希望创建一个编辑器,其中允许用户处理表、斜体和粗体格式等,则应该使用RichTextBox。有关更多信息,请参见RichTextBox 概述。
注意:RichTextBox 内部的流内容的行为并不与其他控件中包含的流内容完全相同。例如,在RichTextBox 中不分栏,因此没有自动调整大小行为。另外,在RichTextBox 中不能使用通常内置在流内容中的功能,例如搜索、查看模式、页面导航和缩放。
 创建流内容
流内容可能很复杂并包含各种元素,包括文本、图像、表甚至像控件这样的UIElement 派生类。若要了解如何创建复杂流内容,掌握下列知识点是非常关键的:
与流相关的类:流内容中使用的每个类都有特定用途。此外,流类之间的层次关系可帮助您了解它们的使用方式。例如,从Block 类派生的类用于包含其他对象,而从Inline 派生的类包含所显示的对象。
内容架构:流文档可能需要大量嵌套元素。内容架构指定了元素之间可能存在的父/子关系。
以下各节将详细介绍上述每个方面。
 与流相关的类
下图演示最常与流内容一起使用的对象:

根据流内容的用途,可以分为两个重要类别:
Block 派生类:也称为“Block 内容元素”,或简称为“Block 元素”。继承自Block 的元素可用于将元素分组到一个公用父级下,或将公用属性应用于某个组。
Inline 派生类:也称为“Inline 内容元素”,或简称为“Inline 元素”。继承自Inline 的元素包含在一个 Block 元素中,或者包含在另一个 Inline 元素中。Inline 元素通常用作在屏幕上呈现的内容的直接容器。例如,一个Paragraph(Block 元素)可包含一个Run(Inline 元素),而Run 实际包含在屏幕上呈现的文本。
下面简要介绍了这两个类别中的每个类。
Block 派生类
Paragraph
Paragraph 通常用于将内容分组到一个段落中。Paragraph 的最简单且最常见的用途是创建文本段落。
复制代码
Some paragraph text.
C#
复制代码
using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class ParagraphExample : Page{public ParagraphExample(){// Create paragraph with some text.Paragraph myParagraph = new Paragraph();myParagraph.Inlines.Add(new Run("Some paragraph text."));// Create a FlowDocument and add the paragraph to it.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(myParagraph);this.Content = myFlowDocument;}}}
不过,也可以包含其他 Inline 派生元素,如下所示。

Section 只用于包含其他Block 派生元素。它不会向其中包含的元素应用任何默认格式。不过,在Section 上设置的任何属性值都适用于其子元素。使用节能够以编程方式循环访问其子级的集合。Section 的使用方式类似于 HTML 中的
标记。
在下面的示例中,在一个Section 下定义了三个段落。该节具有Background 属性值 Red,因此段落的背景色也是红色。
复制代码
Paragraph 1Paragraph 2Paragraph 3

C#
复制代码
using System;using System.Windows;using System.Windows.Media;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class SectionExample : Page{public SectionExample(){// Create three paragraphsParagraph myParagraph1 = new Paragraph(new Run("Paragraph 1"));Paragraph myParagraph2 = new Paragraph(new Run("Paragraph 2"));Paragraph myParagraph3 = new Paragraph(new Run("Paragraph 3"));// Create a Section and add the three paragraphs to it.Section mySection = new Section();mySection.Background = Brushes.Red;mySection.Blocks.Add(myParagraph1);mySection.Blocks.Add(myParagraph2);mySection.Blocks.Add(myParagraph3);// Create a FlowDocument and add the section to it.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(mySection);this.Content = myFlowDocument;}}}
BlockUIContainer
BlockUIContainer 使UIElement 元素(即Button)能够嵌入到 Block 派生的流内容中。InlineUIContainer(参见下文)用于在 Inline 派生的流内容中嵌入UIElement 元素。BlockUIContainer 和InlineUIContainer 很重要,因为除非UIElement 包含在这两个元素之一内部,否则没有其他办法在流内容中使用它。
下面的示例演示如何使用BlockUIContainer 元素在流内容中承载UIElement 对象。
复制代码
A UIElement element may be embedded directly in flow contentby enclosing it in a BlockUIContainer element.The BlockUIContainer element may host no more than one top-levelUIElement. However, other UIElements may be nested within theUIElement contained by an BlockUIContainer element. For example,a StackPanel can be used to host multiple UIElement elements withina BlockUIContainer element.abcxyzA text editor embedded in flow content.

下图显示了此示例的呈现效果。

List
List 用于创建项目符号列表或编号列表。将MarkerStyle 属性设置为TextMarkerStyle 枚举值可确定列表的样式。下面的示例演示如何创建一个简单的列表。
复制代码
List Item 1List Item 2List Item 3
C#
复制代码
using System;using System.Windows;using System.Windows.Media;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class ListExample : Page{public ListExample(){// Create three paragraphsParagraph myParagraph1 = new Paragraph(new Run("List Item 1"));Paragraph myParagraph2 = new Paragraph(new Run("List Item 2"));Paragraph myParagraph3 = new Paragraph(new Run("List Item 3"));// Create the ListItem elements for the List and add the // paragraphs to them.ListItem myListItem1 = new ListItem();myListItem1.Blocks.Add(myParagraph1);ListItem myListItem2 = new ListItem();myListItem2.Blocks.Add(myParagraph2);ListItem myListItem3 = new ListItem();myListItem3.Blocks.Add(myParagraph3);// Create a List and add the three ListItems to it.List myList = new List();myList.ListItems.Add(myListItem1);myList.ListItems.Add(myListItem2);myList.ListItems.Add(myListItem3);// Create a FlowDocument and add the section to it.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(myList);this.Content = myFlowDocument;}}}
注意:List 是唯一一个使用ListItemCollection 来管理子元素的流元素。
Table
Table 用于创建表。Table 类似于Grid 元素,但是它具有更多功能,因此需要更多的资源开销。因为Grid 是一个UIElement,所以除非它包含在BlockUIContainer 或InlineUIContainer 中,否则不能在流内容中使用。有关Table 的更多信息,请参见表概述:
Inline 派生类
运行
Run 用于包含无格式文本。您可能预期Run 对象会在流内容中广泛使用,不过,在标记中不需要显式使用Run 元素。例如,在下面的标记中,第一个Paragraph 显式指定了Run 元素,而第二个却没有。这两个段落生成相同的输出。
复制代码
Paragraph that explicitly uses the Run element.This Paragraph omits the the Run element in markup. It rendersthe same as a Paragraph with Run used explicitly.
注意:在使用代码创建或操作流文档时,需要使用Run。
Span
Span 将其他 Inline 内容元素组织到一起。对于Span 元素中的内容,不应用任何继承呈现。但是,从Span 继承的元素(包括Hyperlink、Bold、Italic 和Underline)确实会向文本应用格式。
下面是Span 的一个示例,它用于包含内联内容,包括文本、一个Bold 元素和一个Button。
复制代码
Text before the Span. Text within the Span isred and this text is inside the Span-derived element Bold.A Span can contain more then text, it can contain any inline content. Forexample, it can contain aor other UIElement, a Floater, a Figure, etc.
下面的屏幕快照显示了此示例的呈现效果。

InlineUIContainer
InlineUIContainer 使UIElement 元素(即像Button 这样的控件)能够嵌入到Inline 内容元素中。此元素是与上面介绍的BlockUIContainer 等效的 Inline 元素。下面的示例使用InlineUIContainer 将一个Button 以内联方式插入到Paragraph 中。
复制代码
Text to precede the button...Text to follow the button...
C#
复制代码
using System;using System.Windows;using System.Windows.Media;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class InlineUIContainerExample : Page{public InlineUIContainerExample(){Run run1 = new Run(" Text to precede the button... ");Run run2 = new Run(" Text to follow the button... ");// Create a new button to be hosted in the paragraph.Button myButton = new Button();myButton.Content = "Click me!";// Create a new InlineUIContainer to contain the Button.InlineUIContainer myInlineUIContainer = new InlineUIContainer();// Set the BaselineAlignment property to "Bottom" so that the // Button aligns properly with the text.myInlineUIContainer.BaselineAlignment = BaselineAlignment.Bottom;// Asign the button as the UI container‘s child.myInlineUIContainer.Child = myButton;// Create the paragraph and add content to it.Paragraph myParagraph = new Paragraph();myParagraph.Inlines.Add(run1);myParagraph.Inlines.Add(myInlineUIContainer);myParagraph.Inlines.Add(run2);// Create a FlowDocument and add the paragraph to it.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(myParagraph);this.Content = myFlowDocument;}}}
注意:不需要在标记中显式使用InlineUIContainer。如果将其省略,编译代码时仍将创建一个InlineUIContainer。
Figure 和 Floater
通过Figure 和Floater,可以使用定位属性在流文档中嵌入内容,这些定位属性可独立于主内容流进行自定义。Figure 或Floater 元素通常用于突出显示或强调内容的某些部分、在主内容流中承载支持图像或其他内容、或者插入不密切相关的内容(例如广告)。
下面的示例演示如何将一个Figure 嵌入到文本段落中。
复制代码
A Figure embeds content into flow content with placement propertiesthat can be customized independently from the primary content flowLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummynibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisienim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortisnisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
C#
复制代码
using System;using System.Windows;using System.Windows.Media;using System.Windows.Controls;using System.Windows.Documents;namespace SDKSample{public partial class FigureExample : Page{public FigureExample(){// Create strings to use as content.string strFigure = "A Figure embeds content into flow content with" +" placement properties that can be customized" +" independently from the primary content flow";string strOther = "Lorem ipsum dolor sit amet, consectetuer adipiscing" +" elit, sed diam nonummy nibh euismod tincidunt ut laoreet" +" dolore magna aliquam erat volutpat. Ut wisi enim ad" +" minim veniam, quis nostrud exerci tation ullamcorper" +" suscipit lobortis nisl ut aliquip ex ea commodo consequat." +" Duis autem vel eum iriure.";// Create a Figure and assign content and layout properties to it.Figure myFigure = new Figure();myFigure.Width = new FigureLength(300);myFigure.Height = new FigureLength(100);myFigure.Background = Brushes.GhostWhite;myFigure.HorizontalAnchor = FigureHorizontalAnchor.PageLeft;Paragraph myFigureParagraph = new Paragraph(new Run(strFigure));myFigureParagraph.FontStyle = FontStyles.Italic;myFigureParagraph.Background = Brushes.Beige;myFigureParagraph.Foreground = Brushes.DarkGreen;myFigure.Blocks.Add(myFigureParagraph);// Create the paragraph and add content to it.Paragraph myParagraph = new Paragraph();myParagraph.Inlines.Add(myFigure);myParagraph.Inlines.Add(new Run(strOther));// Create a FlowDocument and add the paragraph to it.FlowDocument myFlowDocument = new FlowDocument();myFlowDocument.Blocks.Add(myParagraph);this.Content = myFlowDocument;}}}
下图显示了此示例的呈现效果。

Figure 和Floater 在多个方面存在差异,并且用于不同的方案。
Figure:
可定位:可以设置其水平和垂直定位点,以便相对于页面、内容、栏或段落进行停靠。还可以使用其HorizontalOffset 和VerticalOffset 属性指定任意偏移量。
可将其大小调整为栏大小的几倍:可以将Figure 的高度和宽度设置为页面、内容或栏的高度或宽度的倍数。请注意,对于页面和内容,倍数不能大于 1。例如,可以将Figure 的宽度设置为“页面的 0.5 倍”、“内容的 0.25 倍”或“栏的 2 倍”。还可以将高度和宽度设置为绝对像素值。
不分页:如果Figure 中的内容无法容纳在Figure 内部,它会呈现能够容纳的内容部分,而其余内容将丢失
Floater:
无法定位,可在能够为其提供空间的任何位置呈现。不能设置偏移量或锚定Floater。
不能将其大小设置为栏大小的几倍:默认情况下,Floater 的大小为一个栏大小。它有一个可设置为绝对像素值的Width 属性,但是如果此值大于一个栏宽,则将其忽略并将浮动对象的大小设置为一个栏大小。可以通过设置正确的像素宽度,将其大小设置为小于一个栏大小,但不能相对于栏调整大小,因此“栏的 0.5 倍”不是Floater 宽度的有效表达式。Floater 没有高度属性,因此无法设置其高度;其高度取决于内容。
Floater 分页:如果指定宽度的内容超出了一个栏的高度,则浮动对象会断开并显示到下一栏、下一页中等等。
如果希望控制大小和定位,并且确信内容适合于指定的大小,那么Figure 非常适合于放置独立内容。Floater 适合放置流动方式与主页内容类似但独立于主页内容的、具有更大流动自由度的内容。
LineBreak
LineBreak 导致在流内容中发生换行。以下示例说明LineBreak 的用法。
复制代码
Before the LineBreak in Paragraph.After the LineBreak in Paragraph.After two LineBreaks in Paragraph.After a Paragraph with only a LineBreak in it.
下面的屏幕快照显示了此示例的呈现效果。

流集合元素
在上面的多个示例中,BlockCollection 和InlineCollection 用于以编程方式构造流内容。例如,若要向Paragraph 中添加元素,可以使用以下语法:

myParagraph.Inlines.Add(new Run("Some text"));

该语法向Paragraph 的InlineCollection 中添加一个Run。 这与标记中的Paragraph 内部包含的隐式Run 相同。


Some Text


作为使用BlockCollection 的示例,下面的示例创建了一个新的Section,然后使用 Add 方法将一个新的Paragraph 添加到Section 内容中。
C#
复制代码
Section secx = new Section();secx.Blocks.Add(new Paragraph(new Run("A bit of text content...")));
除了向流集合中添加项以外,还可以移除项。 下面的示例删除Span 中的最后一个Inline 元素。
C#
复制代码
spanx.Inlines.Remove(spanx.Inlines.LastInline);
下面的示例从Span 中清除所有内容(Inline 元素)。
C#
复制代码
spanx.Inlines.Clear();
在以编程方式使用流内容时,可能会广泛使用这些集合。
流元素是使用InlineCollection(内联)还是BlockCollection(块)来包含其子元素取决于父级可以包含的子元素的类型(Block 或Inline)。下一节中的内容架构中概述了流内容元素的包容规则。
注意:还有第三种类型的集合可用于流内容,即ListItemCollection,但此集合仅用于List。此外,还有几个集合可用于Table。有关更多信息,请参见表概述。
 内容架构
不同流内容元素的数量是如此之多,因此了解某个元素可包含的子元素的类型是非常困难的。下面的关系图概述了流元素的包容规则。箭头表示可能存在的父/子关系。

如上面的关系图所示,元素可以具有的子元素不一定通过该元素是Block 元素还是Inline 元素来确定。例如,Span(一个Inline 元素)只能具有Inline 子元素,而Figure(也是Inline 元素)只能具有Block 子元素。因此,关系图可用于快速地确定哪些元素可以包含在其他元素中。例如,我们可以使用关系图来确定如何构造RichTextBox 的流内容。
1. 一个RichTextBox 必须包含一个FlowDocument,而后者又必须包含一个派生自Block 的对象。下面是上述关系图中的对应部分。

到此为止,标记可能类似于所示内容。
复制代码

2. 按照该关系图,存在多个可以从中进行选择的Block 元素,包括Paragraph、Section、Table、List 和BlockUIContainer(请参见上面的 Block 派生类)。假设我们需要一个Table。按照上面的关系图,一个Table 包含一个TableRowGroup,后者包含TableRow 元素,这些元素又包含TableCell 元素,而这些元素包含一个Block 派生对象。下面是取自上述关系图中的Table 的对应部分。

下面是对应的标记。
复制代码

3. 同样,TableCell 下需要一个或多个Block 元素。为简单起见,我们在单元格内部放置一些文本。可以使用一个带有Run 元素的Paragraph 来实现该操作。下面是该关系图中的对应部分,它显示Paragraph 可以包含一个Inline 元素,而Run(一个Inline 元素)只能包含纯文本。

下面是标记中的完整示例。
复制代码
Paragraph in a Table Cell.

 自定义文本
通常,文本是流文档中最普遍的内容类型。尽管上面介绍的对象可用于控制文本呈现方式的大多数方面,但还有其他一些自定义文本的方法。本节将对此进行介绍。
文本修饰
使用文本修饰,可以向文本应用下划线、上划线、基线和删除线效果(请参见下图)。这些修饰是使用TextDecorations 属性添加的,该属性由很多对象公开,其中包括Inline、Paragraph、TextBlock 和TextBox。
下面的示例演示如何设置Paragraph 的TextDecorations 属性。
复制代码
This text will render with the strikethrough effect.
C#
复制代码
Paragraph parx = new Paragraph(new Run("This text will render with the strikethrough effect."));parx.TextDecorations = TextDecorations.Strikethrough;
下图显示了此示例的呈现效果。

下面的各图分别显示了上划线、基线和下划线修饰的呈现效果。

版式
Typography 属性由大多数与流相关的内容公开,其中包括TextElement、FlowDocument、TextBlock 和TextBox。此属性用于控制文本的版式特征/变体(即小型大写字母或大型大写字母、上标和下标等)。
下面的示例演示如何设置Typography 属性,其中使用Paragraph 作为示例元素。
复制代码
This text has some altered typography characteristics. Notethat use of an open type font is necessary for most typographicproperties to be effective.0123456789 10 11 12 131/2 2/3 3/4
下图显示了此示例的呈现效果。

作为对比,下图显示了一个具有默认版式属性的类似示例的呈现效果。

下面的示例演示如何以编程方式设置Typography 属性。
C#
复制代码
Paragraph par = new Paragraph();Run runText = new Run("This text has some altered typography characteristics. Note" +"that use of an open type font is necessary for most typographic" +"properties to be effective.");Run runNumerals = new Run("0123456789 10 11 12 13");Run runFractions = new Run("1/2 2/3 3/4");par.Inlines.Add(runText);par.Inlines.Add(new LineBreak());par.Inlines.Add(new LineBreak());par.Inlines.Add(runNumerals);par.Inlines.Add(new LineBreak());par.Inlines.Add(new LineBreak());par.Inlines.Add(runFractions);par.TextAlignment = TextAlignment.Left;par.FontSize = 18;par.FontFamily = new FontFamily("Palatino Linotype");par.Typography.NumeralStyle = FontNumeralStyle.OldStyle;par.Typography.Fraction = FontFraction.Stacked;par.Typography.Variants = FontVariants.Inferior;
有关版式的更多信息,请参见Windows Presentation Foundation 中的版式。
 请参见
概念
优化性能:文本
SDK 查看器演示
流内容元素示例
Windows Presentation Foundation 中的版式
流内容元素帮助主题
TextElement 内容模型概述
RichTextBox 概述
Windows Presentation Foundation 中的文档
表概述
批注概述