FlowDocument 建構函式

定義

初始化 FlowDocument 類別的新執行個體。Initializes a new instance of the FlowDocument class.

多載

FlowDocument()

初始化 FlowDocument 類別的新的空執行個體。Initializes a new, empty instance of the FlowDocument class.

FlowDocument(Block)

初始化 FlowDocument 類別的新執行個體,並加入指定的 Block 項目做為初始內容。Initializes a new instance of the FlowDocument class, adding a specified Block element as the initial content.

FlowDocument()

初始化 FlowDocument 類別的新的空執行個體。Initializes a new, empty instance of the FlowDocument class.

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

適用於

FlowDocument(Block)

初始化 FlowDocument 類別的新執行個體,並加入指定的 Block 項目做為初始內容。Initializes a new instance of the FlowDocument class, adding a specified Block element as the initial content.

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 類別的物件,會當做初始內容加入。An object deriving from the abstract Block class, to be added as the initial content.

例外狀況

blocknullblock is null.

範例

下列範例示範如何使用此函數。The following example demonstrates the use of this constructor. 在此情況下,會 FlowDocument 包含一個流程元素區塊結構,由一個在段落中嵌套的文字執行所組成。In this case, the FlowDocument contains a flow element block structure consisting of a text run nested in a paragraph.

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 其中包含資料表。The following example programmatically constructs a simple 2 x 2 table and then uses the FlowDocument constructor to create a new FlowDocument containing the table. 雖然使用較複雜的 flow 元素區塊結構,但使用此函式的方式與上述範例中的相同。Though a somewhat more complicated flow element block structure is used, use of the constructor is the same as in the preceding example.

// 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 包括 BlockUIContainerListParagraphSectionTableValid input types for block include BlockUIContainer, List, Paragraph, Section, and Table.

適用於