共用方式為


HOW TO:透過 Inlines 屬性管理非固定格式內容項目

這些範例示範可以在內嵌 (Inline) 的非固定格式內容項目上 (和這類項目的容器,如 TextBlock),透過 Inlines 屬性執行的幾個較常見的作業。 這個屬性用於加入和移除 InlineCollection 中的項目。 具有 Inlines 屬性的非固定格式內容項目包括:

雖然這些範例中都是使用 Span 做為非固定格式內容項目,但這些方法也適用於裝載 InlineCollection 集合的所有項目或控制項。

範例

下列範例會建立新的 Span 物件,然後使用 Add 方法加入兩個文字執行做為 Span 的內容子系。

            Dim spanx As New Span()
            spanx.Inlines.Add(New Run("A bit of text content..."))
            spanx.Inlines.Add(New Run("A bit more text content..."))
Span spanx = new Span();
spanx.Inlines.Add(new Run("A bit of text content..."));
spanx.Inlines.Add(new Run("A bit more text content..."));

下列範例會建立新的 Run 項目,並將其插入至 Span 的開頭。

            Dim runx As New Run("Text to insert...")
            spanx.Inlines.InsertBefore(spanx.Inlines.FirstInline, runx)
Run runx = new Run("Text to insert...");
spanx.Inlines.InsertBefore(spanx.Inlines.FirstInline, runx);

下列範例會取得 Span 中包含的最上層 Inline 項目。

            Dim countTopLevelInlines As Integer = spanx.Inlines.Count
int countTopLevelInlines = spanx.Inlines.Count;

下列範例會刪除 Span 中的最後一個 Inline 項目。

            spanx.Inlines.Remove(spanx.Inlines.LastInline)
spanx.Inlines.Remove(spanx.Inlines.LastInline);

下列範例會清除 Span 中的所有內容 (Inline 項目)。

            spanx.Inlines.Clear()
spanx.Inlines.Clear();

請參閱

工作

HOW TO:透過 Blocks 屬性管理 FlowDocument

HOW TO:透過 Columns 屬性管理資料表的資料行

HOW TO:透過 RowGroups 屬性管理資料表的資料列群組

參考

BlockCollection

InlineCollection

ListItemCollection

概念

非固定格式文件概觀