ParagraphStyle Class
Represents a style which can be applied to one or more Paragraphs within a document content.
public sealed class ParagraphStyle : Style
Public NotInheritable Class ParagraphStyle
Inherits Style
- Inheritance:
- System.ObjectParagraphStyle
Remarks
Styles provide a way to format your document in a consistent way so when you change your formatting options on a style, all document elements referencing that style will be changed.
To apply a ParagraphStyle to a Paragraph, set it to a Style property on a ParagraphFormat.
For an example how to apply ParagraphStyle to a Paragraph, see styles example.
Constructors
ParagraphStyle(String)
Initializes a new instance of the ParagraphStyle class.
Parameters
name
- System.String
The style name.
Properties
BaseStyle
Gets or sets the style on which this style is based.
Property Value
The base style.
CharacterFormat
Gets or sets the character format.
public CharacterFormat CharacterFormat { get; set; }
Public Property CharacterFormat As CharacterFormat
Property Value
The character format.
Document
Gets the owner document.
public override DocumentModel Document { get; protected set; }
Public Overrides Property Document As DocumentModel
Property Value
The owner document.
Overrides
ListFormat
Gets or sets the list format.
Property Value
The list format.
Remarks
List (for example, ordered - with numbers, or unordered - with bullets) appearance in GemBox.Document is defined through ListFormat class that is set on Paragraph's ListFormat property or ParagraphStyle's ListFormat property.
ListFormat is different from other formats (ParagraphFormat and CharacterFormat) because it doesn't directly contain any formatting properties.
It contains a reference to a ListStyle which exposes ListLevelFormats for every list (indentation) level through its ListLevelFormats property.
ListLevelFormats contain direct formatting properties that affect the appearance of the list. Every ListStyle contains exactly 9 ListLevelFormats, one for each possible list (indentation) level.
Paragraph's list (indentation) level can be adjusted with ListLevelNumber property. Paragraph's list-related formatting will then be collected from the ListLevelFormat instance contained in the ListLevelFormats at the position ListLevelNumber. This ListLevelFormat can also be retrieved from the ListLevelFormat property.
ListLevelFormat retrieved from the ListLevelFormat property can be additionally modified to enable overriding property values of ListLevelFormat instance contained in the ListLevelFormats at the position ListLevelNumber on a Paragraph or ParagraphStyle basis.
To create a list in a document, first ListStyle instance has to be created from one of the predefined list style types specified with ListTemplateType enumeration. After that, ListFormat can be created with a specified ListStyle and assigned to a Paragraph's ListFormat property. For a complete example, see Lists example.
If ListStyle is not referenced from anywhere in the document (from any Paragraph or ParagraphStyle, then it won't be saved to a Word Document (DOCX) file, unless it is added to Styles collection.
Paragraph's list content, which prefixes paragraph content, is represented by ListItem type.
ListItems are not permanently stored in model nor they are written to file formats which fully support ListFormat, instead they are recreated each time CalculateListItems() method is called.
If document content or formatting is changed, then CalculateListItems() method should be called again to retrieve the latest list items.
For convenience, after calling CalculateListItems() method, ListItem can also be retrieved from ListItem property.
After calling System.IDisposable.Dispose() on System.Collections.Generic.IEnumerator<T> instance retrieved by calling System.Collections.Generic.IEnumerable<T>.GetEnumerator() on instance returned from CalculateListItems() method, paragraph's ListItem property will be null even if paragraph's IsList is true. This enables easy iteration over ListItems returned from CalculateListItems() method by using foreach statement and removing all references to ListItems after the iteration is finished.
NextParagraphStyle
Gets or sets the style that will be assigned automatically to following paragraph.
public ParagraphStyle NextParagraphStyle { get; set; }
Public Property NextParagraphStyle As ParagraphStyle
Property Value
The next paragraph style.
Remarks
This property is simply written to Word file and has no effect on the behavior of this library.
ParagraphFormat
Gets or sets the paragraph format which shall be applied to the referencing ParagraphStyle.
public ParagraphFormat ParagraphFormat { get; set; }
Public Property ParagraphFormat As ParagraphFormat
Property Value
The paragraph format which shall be applied to the referencing ParagraphStyle.
Remarks
For more information about paragraph formatting, see paragraph formatting example.
StyleType
Gets the type of the style.
public override StyleType StyleType { get; }
Public Overrides ReadOnly Property StyleType As StyleType
Property Value
The type of the style.
Overrides
Inherited Properties
Name | Gets or sets the name of the style. (Inherited from Style) |
Inherited Methods
CreateStyle(StyleTemplateType, DocumentModel) | Creates one of the predefined styles. (Inherited from Style) |
ToString() | Returns a System.String that represents this Style instance. (Inherited from Style) |