FlowDocument 构造函数

定义

初始化 FlowDocument 类的新实例。

重载

FlowDocument()

初始化 FlowDocument 类的新的空实例。

FlowDocument(Block)

初始化 FlowDocument 类的一个新实例,将指定的 Block 元素作为初始内容添加到实例中。

FlowDocument()

初始化 FlowDocument 类的新的空实例。

public:
 FlowDocument();
public FlowDocument ();
Public Sub New ()

适用于

FlowDocument(Block)

初始化 FlowDocument 类的一个新实例,将指定的 Block 元素作为初始内容添加到实例中。

public:
 FlowDocument(System::Windows::Documents::Block ^ block);
public FlowDocument (System.Windows.Documents.Block block);
new System.Windows.Documents.FlowDocument : System.Windows.Documents.Block -> System.Windows.Documents.FlowDocument
Public Sub New (block As Block)

参数

block
Block

要作为初始内容添加的、从 Block 抽象类派生的对象。

例外

blocknull

示例

以下示例演示了此构造函数的用法。 在这种情况下, FlowDocument 包含一个流元素块结构,该结构由嵌套在段落中的文本运行组成。

FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("A bit of text content...")));
Dim flowDocSimple As New FlowDocument(New Paragraph(New Run("A bit of text content...")))

以下示例以编程方式构造一个简单的 2 x 2 表,然后使用 构造 FlowDocument 函数创建包含该表的新 FlowDocument 。 尽管使用了更复杂的流元素块结构,但构造函数的使用与前面的示例相同。

// A paragraph with sample text will serve as table content.
Paragraph tableText = new Paragraph(new Run("A bit of text content..."));

Table sampleTable = new Table();

// Create and add a couple of columns.
sampleTable.Columns.Add(new TableColumn());
sampleTable.Columns.Add(new TableColumn());

// Create and add a row group and a couple of rows.
sampleTable.RowGroups.Add(new TableRowGroup());
sampleTable.RowGroups[0].Rows.Add(new TableRow());
sampleTable.RowGroups[0].Rows.Add(new TableRow());

// Create four cells initialized with the sample text paragraph.
sampleTable.RowGroups[0].Rows[0].Cells.Add(new TableCell(tableText));
sampleTable.RowGroups[0].Rows[0].Cells.Add(new TableCell(tableText));
sampleTable.RowGroups[0].Rows[1].Cells.Add(new TableCell(tableText));
sampleTable.RowGroups[0].Rows[1].Cells.Add(new TableCell(tableText));

// Finally, use the FlowDocument constructor to create a new FlowDocument containing 
// the table constructed above.
FlowDocument flowDoc = new FlowDocument(sampleTable);
    ' A paragraph with sample text will serve as table content.
    Dim tableText As New Paragraph(New Run("A bit of text content..."))

    Dim sampleTable As New Table()

    ' Create and add a couple of columns.
    sampleTable.Columns.Add(New TableColumn())
    sampleTable.Columns.Add(New TableColumn())

    ' Create and add a row group and a couple of rows.
    sampleTable.RowGroups.Add(New TableRowGroup())
    sampleTable.RowGroups(0).Rows.Add(New TableRow())
    sampleTable.RowGroups(0).Rows.Add(New TableRow())

    ' Create four cells initialized with the sample text paragraph.
    sampleTable.RowGroups(0).Rows(0).Cells.Add(New TableCell(tableText))
    sampleTable.RowGroups(0).Rows(0).Cells.Add(New TableCell(tableText))
    sampleTable.RowGroups(0).Rows(1).Cells.Add(New TableCell(tableText))
    sampleTable.RowGroups(0).Rows(1).Cells.Add(New TableCell(tableText))

    ' Finally, use the FlowDocument constructor to create a new FlowDocument containing 
    ' the table constructed above.
Dim flowDocTable As New FlowDocument(sampleTable)

注解

的有效输入类型block包括 BlockUIContainer、、ListParagraphSectionTable

适用于