Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Style Properties

Style property is part of the style system, used to hold information about a formatting value of the document elements. It can be used to check if the value is local or it is inherited from base style. Information about how the style system works and how values are inherited from base styles can be found in the Style Evaluation and Inheritance section of the Styles article.

Style Property Implementation Overview

Style properties are exposed through IStyleProperty interface, which contains the following properties and methods:

  • LocalValue: Used to get or set the local value. If it is not set, the value is null.

  • HasLocalValue: Returns value indicating whether the style property has local value.

  • GetActualValue(): Returns the actual value of the property. This value is evaluated on every call by the style system using the evaluation rules described in the Styles article.

  • ClearValue(): Clears the local value.

  • PropertyDefinition: The property definition is exposed through the IStylePropertyDefinition interface and specifies some details for the style property as:

    • PropertyName: Returns the name of the style property.
    • StylePropertyType: Returns the type of the style property.
    • Validation: Used to determine if a value is valid for this style property.
    • GetDefaultValueAsObject(): This method returns the default value as object.

Some of the style properties always contain local value and are normally referred to as local style properties. They are used only by the document elements and their values are not respected by styles and style inheritance.

Style Property Definitions

Style property definition is represented by the StylePropertyDefinition class and can be accessed from the style property itself (through its base interface IStylePropertyDefinition) or as a static member of Run, Paragraph, Table, TableRow and TableCell document elements. Style property definitions specify the following details of the style property:

  • PropertyName: Specifies the name of the style property.
  • DefaultValue: Specifies the default value of the style property.
  • StylePropertyType: Specifies the type of the style property as StylePropertyType enumeration.
  • Validation: Used to determine if a value is valid for the style property associated with this style property definition.

Using Style Properties

Style Properties in Document Elements

Document elements expose sets of style properties through the Properties property. For convenience, style properties can be also used through CLR shorthand properties exposed directly from the document elements. Shorthand property getter gets the actual value of the property while property setter sets the local value of the property.

Example 1 is an example for equivalent getting of a value with CLR property and style property.

Example 1: Get a value

bool keepOnOnePageActualValueShorthand = paragraph.KeepOnOnePage; 
bool keepOnOnePageActualValue = paragraph.Properties.KeepOnOnePage.GetActualValue().Value; 

Example 2 is an example for an equivalent setting of a value with CLR property and style property.

Example 2: Set a value

paragraph.KeepOnOnePage = true; 
paragraph.Properties.KeepOnOnePage.LocalValue = true; 

Style Properties in Styles

The style properties in a style are accessible through the following property sets: CharacterProperties, ParagraphProperties, TableProperties, TableRowProperties and TableCellProperties.

Example 3 illustrates how to get the local value of a style property in a style.

Example 3: Get the local value

bool? keepOnOnePage = style.ParagraphProperties.KeepOnOnePage.LocalValue; 

Example 4 shows how to get the actual value of style property in style.

Example 4: Get the actual value

bool keepOnOnePage = style.ParagraphProperties.KeepOnOnePage.GetActualValue().Value; 

Style Properties Default Values

The default values of all style properties are available in their StylePropertyDefinitions and cannot be changed. To set the default values of properties for a particular document, you can change the default styles for the document.

The code in Example 5 illustrates how to get the default value for a style property.

Example 5: Get the default value

bool keepOnOnePageDefaultValue = Paragraph.KeepOnOnePagePropertyDefinition.DefaultValue.Value; 

Following is a list of all available style properties and their default values:

Name Description Default Value
CharacterProperties
FontFamily The font family. Verdana
FontSize The size of the font. The value is in device independent pixels (1/96 inch). 13.3333333333333
FontStyle The font style. Normal
FontWeight The font weight. Normal
ForegroundColor The foreground color. Black
HighlightColor The color of the highlight. Transparent
BaselineAlignment The baseline alignment. Baseline
Strikethrough The strikethrough. False
BackgroundColor The color of the background. Transparent
ShadingPatternColor A value indicating the color for any foreground pattern used in this shading. Transparent
ShadingPattern A value indicating the pattern which shall be used to lay the pattern color over the background color for this shading. Clear
UnderlineColor The color for the underlining. Auto(#FF000000)
UnderlinePattern A value indicating the pattern which shall be used to create the underlining applied beneath the text. None
FlowDirection The flow direction. LeftToRight
ParagraphProperties
FlowDirection The flow direction. LeftToRight
TextAlignment The paragraph text alignment. Left
SpacingBefore The spacing that should be added above the first line in a paragraph. The value is in device independent pixels (1/96 inch). 0
AutomaticSpacingBefore A value indicating whether a consumer shall automatically determine the spacing before the paragraph based on its contents the automatic spacing after. False
SpacingAfter The spacing that should be added after the last line in a paragraph. The value is in device independent pixels (1/96 inch). 0
AutomaticSpacingAfter A value indicating whether a consumer shall automatically determine the spacing after the paragraph based on its contents the automatic spacing after. False
LineSpacing The value indicating the amount of vertical spacing between lines of text within a paragraph. If is Auto then the line height value times the value of the property, otherwise the value is in device independent pixels (1/96 inch). 1
LineSpacingType The value indicating how the spacing between lines is calculated. Auto
KeepOnOnePage A value indicating if this paragraph should be rendered on one page when the document is shown in page view mode. False
KeepWithNextParagraph A value indicating if this paragraph should be rendered at least partly on the one page with the following paragraph when this is possible and when the document is shown in page view mode. False
OutlineLevel A value indicating the outline level. The outline level defines the level of this paragraph in TOC field. None
ApplyEastAsianLineBreakingRules A value indicating whether East-Asian line breaking rules are applied to this paragraph. True
PageBreakBefore A value indicating if this paragraph should be rendered on new page when the document is shown in page view mode. False
Borders The paragraph borders. None
ContextualSpacing A value indicating whether spacing before/after are ignored when preceding/following paragraph has same paragraph style. False
MirrorIndents A value indicating whether left and right indents should be swapped on odd pages. False
BackgroundColor The color of the background. Transparent
ShadingPatternColor A value indicating the color for any foreground pattern used in this shading. Transparent
ShadingPattern A value indicating the pattern which shall be used to lay the pattern color over the background color for this shading. Clear
FirstLineIndent A value indicating the additional indentation which shall be applied to the first line of the paragraph. The value is in device independent pixels (1/96 inch). 0
HangingIndent A value which shall be removed from the indentation of the first line of the paragraph, by moving the indentation on the first line back towards the beginning of the direction of text flow. The value is in device independent pixels (1/96 inch). 0
LeftIndent A value indicating the indentation which shall be applied to the left side of the whole paragraph. The value is in device independent pixels (1/96 inch). 0
RightIndent A value indicating the indentation which shall be applied to the right side of the whole paragraph. The value is in device independent pixels (1/96 inch). 0
AllowOverflowPunctuation A value indicating whether the last punctuation character on a line can overflow in paragraph margin/indent. This property cannot be derived from a style. True
TabStops The tab stops in the paragraph.
ListId A value indicating that the paragraph is referencing a list. -1
ListLevel A value indicating that the paragraph is referencing list level. -1
TableProperties
Alignment The alignment of the table. Left
BackgroundColor The color of the background. Transparent
ShadingPatternColor A value indicating the color for any foreground pattern used in this shading. Transparent
ShadingPattern A value indicating the pattern which shall be used to lay the pattern color over the background color for this shading. Clear
Borders The table border. None
TableCellPadding Default padding of the cells inside the table. 0, 0, 0, 0
TableCellSpacing A value indicating the spacing between adjacent cells and the edges of the table. The value is in device independent pixels (1/96 inch). 0
Indent A value which shall be added before the leading edge of the table. The value is in device independent pixels (1/96 inch). 0
RowBanding The number of banded rows. 0
ColumnBanding The number of banded columns. 0
FlowDirection The flow direction of cells inside the table. This property cannot be derived from a style. LeftToRight
PreferredWidth The preferred width. This property cannot be derived from a style. Auto
Looks The value indicating which components of the conditional style should be applied if such exists. This property cannot be derived from a style. BandedRows, BandedColumns
LayoutType A value indicating which algorithm shall be used to lay out the content of the table. This property cannot be derived from a style. AutoFit
Overlap A value indicating whether this floating table shall allow other floating tables to overlap its extents. This property cannot be derived from a style. True
TableRowProperties
TableCellSpacing A value indicating the spacing between adjacent cells and the edges of the table. The value is in device independent pixels (1/96 inch). 0
RepeatOnEveryPage A value indicating whether this row should be repeated on every new page. This property cannot be derived from a style. False
CanSplit A value indicating whether the content of the row can be split across multiple pages. This property cannot be derived from a style. True
Height The height. This property cannot be derived from a style. Auto
TableCellProperties
Borders The borders. None
BackgroundColor The color of the background. Transparent
ShadingPatternColor A value indicating the color for any foreground pattern used in this shading. Transparent
ShadingPattern A value indicating the pattern which shall be used to lay the pattern color over the background color for this shading. Clear
Padding The padding. 7.68, 0, 7.68, 0
ColumnSpan The column span. This property cannot be derived from a style. 1
RowSpan The row span. This property cannot be derived from a style. 1
IgnoreCellMarkerInRowHeightCalculation A value indicating whether cell marker will be ignored when row height is calculated. This property cannot be derived from a style. False
CanWrapContent A value indicating whether the content can be wrapped during the table layout. This property cannot be derived from a style. True
PreferredWidth The preferred width. This property cannot be derived from a style. Auto
VerticalAlignment The vertical alignment. This property cannot be derived from a style. Top
TextDirection The text direction. This property cannot be derived from a style. LeftToRightTopToBottom
SectionProperties
HasDifferentFirstPageHeaderFooter Has different first page header footer. False
PageOrientation Page orientation property. Rotate0
PageSize Page size property. The width and height are in device independent pixels (1/96 inch). 816,1056
PageMargins Page margins property. 96, 96, 96, 96
HeaderTopMargin Header top margin property. The value is in device independent pixels (1/96 inch). 48
FooterBottomMargin Footer bottom margin property. The value is in device independent pixels (1/96 inch). 48
SectionType Section type property. NextPage
VerticalAlignment Vertical alignment property. Top
ChapterSeparatorCharacter Chapter separator character that shall appear between the chapter heading style index and the page number.
ChapterHeadingStyleIndex Index of the chapter heading style.
PageNumberFormat Page number format for the page numbering in the current section.
StartingPageNumber Starting page number. This number appears on the first page of the section.
DocumentProperties
HasDifferentEvenOddPageHeadersFooters A value indicating whether pages in this document will have different headers and footers for even and odd pages. False
ViewType A value indicating the view type of the document. PrintLayout
DefaultTabStopWidth Style property used to determine the default width value which shall be used when a tab stop should be generated. The value is in device independent pixels (1/96 inch). 48

See Also

In this article