Class Container
Represents a container element within a Word document, which can hold other content elements like paragraphs, tables, and images.
Implements
Inherited Members
Namespace: IronWord.Models
Assembly: IronWord.dll
Syntax
public class Container : ParentElement
Container is the object that holds the body of a Word document, the paragraphs, tables, and images that make up its content. A developer works with it as the top-level home for content elements, adding children to it and reading back the text and tables it holds, and it also carries the document-wide defaults that styling falls back to.
A container is created with new Container(), or with new Container(params ContentElement[]) to seed it with an initial set of child elements in one call. Content is added through AddChild, which accepts one or more IWordDocumentObject items such as paragraphs, runs, images, shapes, and text. As the remarks note, paragraphs and other content added this way are placed into the last section in the document, so the container manages where new content lands.
Beyond holding content, a container owns the document's default styles and color and style banks. DefaultParagraphStyle, DefaultTableStyle, and DefaultTextStyle set the baseline a ParagraphStyle, TableStyle, or TextStyle falls back to when an element does not override it, while BuiltInColors and BuiltInStyles expose the registered colors and styles available across the document. From its ParentElement base it also inherits Texts, Tables, and Children for reading the content back, plus LogObjectTree for inspecting the structure during development. Setting the defaults once keeps formatting consistent without repeating style assignments on every element.
var body = new Container();
body.DefaultTextStyle = new TextStyle();
body.AddChild(new Paragraph());The document element tutorial walks through how content elements nest, the log object tree example inspects the structure, and the add paragraph example adds content.
Constructors
Container()
Initializes a new instance of the Container class.
Declaration
public Container()
Container(ContentElement[])
Initializes a new instance of the Container class with the specified child elements.
Declaration
public Container(params ContentElement[] children)
Parameters
| Type | Name | Description |
|---|---|---|
| ContentElement[] | children | The child elements to be added. |
Properties
BuiltInColors
Gets or sets the list of built-in and custom colors in the document.
Declaration
public Dictionary<string, Dictionary<string, Color>> BuiltInColors { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.Dictionary<System.String, Color>> |
BuiltInStyles
Gets or sets the list of built-in and custom styles in the document.
Declaration
public Dictionary<string, BaseStyle> BuiltInStyles { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<System.String, BaseStyle> |
DefaultParagraphStyle
Gets or sets the document paragraph default style.
Declaration
public ParagraphStyle DefaultParagraphStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| ParagraphStyle |
DefaultTableStyle
Gets or sets the document default table style.
Declaration
public TableStyle DefaultTableStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| TableStyle |
DefaultTextStyle
Gets or sets the document default text style.
Declaration
public TextStyle DefaultTextStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| TextStyle |
Methods
AddChild(IWordDocumentObject[])
Adds one or more child content elements to the current content element.
Declaration
public override void AddChild(params IWordDocumentObject[] children)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Abstractions.Word.IWordDocumentObject[] | children | The content elements to be added as children. |
Overrides
Remarks
Paragraphs, runs, images, shapes, and text will automatically be added to the last section in the document.