--- title: "TextElement Content Model Overview" ms.date: "03/30/2017" ms.topic: overview dev_langs: - "csharp" - "vb" helpviewer_keywords: - "documents [WPF], flow documents" - "TextElement content model [WPF]" - "flow content elements [WPF], TextElement content model" ms.assetid: d0a7791c-b090-438c-812f-b9d009d83ee9 --- # TextElement Content Model Overview This content model overview describes the supported content for a . The class is a type of . A content model describes what objects/elements can be contained in others. This overview summarizes the content model used for objects derived from . For more information, see [Flow Document Overview](flow-document-overview.md). ## Content Model Diagram The following diagram summarizes the content model for classes derived from as well as how other non- `TextElement` classes fit into this model. ![Diagram: Flow content containment schema](./media/flow-content-schema.png "Flow_Content_Schema") As can be seen from the preceding diagram, the children allowed for an element are not necessarily determined by whether a class is derived from the class or an class. For example, a (an -derived class) can only have child elements, but a (also an -derived class) can only have child elements. Therefore, a diagram is useful for quickly determining what element can be contained in another. As an example, let's use the diagram to determine how to construct the flow content of a . 1. A must contain a which in turn must contain a -derived object. The following is the corresponding segment from the preceding diagram. ![Diagram: RichTextBox containment rules](./media/flow-ovw-schemawalkthrough1.png "Flow_Ovw_SchemaWalkThrough1") Thus far, this is what the markup might look like. [!code-xaml[FlowOvwSnippets_snip#SchemaWalkThrough1](~/samples/snippets/csharp/VS_Snippets_Wpf/FlowOvwSnippets_snip/CS/MiscSnippets.xaml#schemawalkthrough1)] 2. According to the diagram, there are several elements to choose from including , , , , and (see Block-derived classes in the preceding diagram). Let's say we want a . According to the preceding diagram, a contains a containing elements, which contain elements which contain a -derived object. The following is the corresponding segment for taken from the preceding diagram. ![Diagram: Parent/child schema for Table](./media/flow-ovw-schemawalkthrough2.png "Flow_Ovw_SchemaWalkThrough2") The following is the corresponding markup. [!code-xaml[FlowOvwSnippets_snip#SchemaWalkThrough2](~/samples/snippets/csharp/VS_Snippets_Wpf/FlowOvwSnippets_snip/CS/MiscSnippets.xaml#schemawalkthrough2)] 3. Again, one or more elements are required underneath a . To make it simple, let's place some text inside the cell. We can do this using a with a element. The following is the corresponding segments from the diagram showing that a can take an element and that a (an element) can only take plain text. ![Diagram: Parent/child schema for Paragraph](./media/flow-ovw-schemawalkthrough3.png "Flow_Ovw_SchemaWalkThrough3") ![Diagram: Parent/Child schema for Run](./media/flow-ovw-schemawalkthrough4.png "Flow_Ovw_SchemaWalkThrough4") The following is the entire example in markup. [!code-xaml[FlowOvwSnippets_snip#SchemaExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/FlowOvwSnippets_snip/CS/SchemaExample.xaml#schemaexamplewholepage)] ## Working with TextElement Content Programmatically The contents of a is made up by collections and so programmatically manipulating the contents of objects is done by working with these collections. There are three different collections used by -derived classes: - : Represents a collection of elements. defines the allowable child content of the , , and elements. - : Represents a collection of elements. defines the allowable child content of the , , , , , and elements. - : A flow content element that represents a particular content item in an ordered or unordered . You can manipulate (add or remove items) from these collections using the respective properties of **Inlines**, **Blocks**, and **ListItems**. The following examples show how to manipulate the contents of a Span using the **Inlines** property. > [!NOTE] > Table uses several collections to manipulate its contents, but they are not covered here. For more information, see [Table Overview](table-overview.md). The following example creates a new object, and then uses the `Add` method to add two text runs as content children of the . [!code-csharp[SpanSnippets#_SpanInlinesAdd](~/samples/snippets/csharp/VS_Snippets_Wpf/SpanSnippets/CSharp/Window1.xaml.cs#_spaninlinesadd)] [!code-vb[SpanSnippets#_SpanInlinesAdd](~/samples/snippets/visualbasic/VS_Snippets_Wpf/SpanSnippets/visualbasic/window1.xaml.vb#_spaninlinesadd)] The following example creates a new element and inserts it at the beginning of the . [!code-csharp[SpanSnippets#_SpanInlinesInsert](~/samples/snippets/csharp/VS_Snippets_Wpf/SpanSnippets/CSharp/Window1.xaml.cs#_spaninlinesinsert)] [!code-vb[SpanSnippets#_SpanInlinesInsert](~/samples/snippets/visualbasic/VS_Snippets_Wpf/SpanSnippets/visualbasic/window1.xaml.vb#_spaninlinesinsert)] The following example deletes the last element in the . [!code-csharp[SpanSnippets#_SpanInlinesRemoveLast](~/samples/snippets/csharp/VS_Snippets_Wpf/SpanSnippets/CSharp/Window1.xaml.cs#_spaninlinesremovelast)] [!code-vb[SpanSnippets#_SpanInlinesRemoveLast](~/samples/snippets/visualbasic/VS_Snippets_Wpf/SpanSnippets/visualbasic/window1.xaml.vb#_spaninlinesremovelast)] The following example clears all of the contents ( elements) from the . [!code-csharp[SpanSnippets#_SpanInlinesClear](~/samples/snippets/csharp/VS_Snippets_Wpf/SpanSnippets/CSharp/Window1.xaml.cs#_spaninlinesclear)] [!code-vb[SpanSnippets#_SpanInlinesClear](~/samples/snippets/visualbasic/VS_Snippets_Wpf/SpanSnippets/visualbasic/window1.xaml.vb#_spaninlinesclear)] ## Types That Share This Content Model The following types inherit from the class and may be used to display the content described in this overview. , , , , , , , , , , , , , , . Note that this list only includes nonabstract types distributed with the Windows SDK. You may use other types that inherit from . ## Types That Can Contain TextElement Objects See [WPF Content Model](../controls/wpf-content-model.md). ## See also - [Manipulate a FlowDocument through the Blocks Property](how-to-manipulate-a-flowdocument-through-the-blocks-property.md) - [Manipulate Flow Content Elements through the Blocks Property](how-to-manipulate-flow-content-elements-through-the-blocks-property.md) - [Manipulate a FlowDocument through the Blocks Property](how-to-manipulate-a-flowdocument-through-the-blocks-property.md) - [Manipulate a Table's Columns through the Columns Property](how-to-manipulate-table-columns-through-the-columns-property.md) - [Manipulate a Table's Row Groups through the RowGroups Property](how-to-manipulate-table-row-groups-through-the-rowgroups-property.md)