Back to Devexpress

ParagraphStyle.LinkedStyle Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-paragraphstyle-6d32421f.md

latest5.3 KB
Original Source

ParagraphStyle.LinkedStyle Property

Gets or sets the linked style for the current style.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
CharacterStyle LinkedStyle { get; set; }
vb
Property LinkedStyle As CharacterStyle

Property Value

TypeDescription
CharacterStyle

A ParagraphStyle object representing a paragraph style linked to a current style

|

Remarks

A linked style can act as a paragraph style or a character style, depending on the range to which it is applied.

If a linked style is applied to a selection which does not include an entire paragraph, the selected text is formatted with the character formatting settings of the linked styles.

If a selection includes an entire paragraph, both character and paragraph formatting settings are applied.

If a selection is just a caret position and contains no characters, the linked style behaves like a paragraph style.

You should specify the LinkedStyle property only once, for one of the linked styles.

Note

Assigning a style via the LinkedStyle property results in overwriting the corresponding settings of the style to which the style becomes linked. So you are advised to link styles first, and specify their settings afterwards.

The code sample below demonstrates how to synchronize a paragraph and character style to create a linked style.

csharp
ParagraphStyle annotationStyle = document.ParagraphStyles["Annotation"];

document.BeginUpdate();

//Create a new paragraph style
//and set the required settings
annotationStyle = document.ParagraphStyles.CreateNew();
annotationStyle.Name = "Annotation";
annotationStyle.Alignment = ParagraphAlignment.Right;
annotationStyle.LineSpacingMultiplier = 1.5f;
annotationStyle.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
annotationStyle.FirstLineIndent = 3;
document.ParagraphStyles.Add(annotationStyle);

//Create a new character style and link it
//to the custom paragraph style
CharacterStyle annotationCharStyle = document.CharacterStyles.CreateNew();
annotationCharStyle.Name = "AnnotationChar";
document.CharacterStyles.Add(annotationCharStyle);
annotationCharStyle.LinkedStyle = annotationStyle;

//Specify the style options
annotationCharStyle.Italic = true;
annotationCharStyle.FontSize = 12;
annotationCharStyle.FontName = "Segoe UI";
annotationCharStyle.ForeColor = Color.Gray;
document.EndUpdate();

//Apply the created style to the first paragraph of the annotation
document.Paragraphs[1].Style = annotationStyle;

//Apply the linked style to the range of the annotation's second paragraph
CharacterProperties annotationProperties = document.BeginUpdateCharacters(document.Paragraphs[2].Range);
annotationProperties.Style = annotationCharStyle;
document.EndUpdateCharacters(annotationProperties);
vb
Dim annotationStyle As ParagraphStyle = document.ParagraphStyles("Annotation")

document.BeginUpdate()

'Create a new paragraph style
'and set the required settings
annotationStyle = document.ParagraphStyles.CreateNew()
annotationStyle.Name = "Annotation"
annotationStyle.Alignment = ParagraphAlignment.Right
annotationStyle.LineSpacingMultiplier = 1.5F
annotationStyle.FirstLineIndentType = ParagraphFirstLineIndent.Hanging
annotationStyle.FirstLineIndent = 3
document.ParagraphStyles.Add(annotationStyle)

'Create a new character style and link it
'to the custom paragraph style
Dim annotationCharStyle As CharacterStyle = document.CharacterStyles.CreateNew()
annotationCharStyle.Name = "AnnotationChar"
document.CharacterStyles.Add(annotationCharStyle)
annotationCharStyle.LinkedStyle = annotationStyle

'Specify the style options
annotationCharStyle.Italic = True
annotationCharStyle.FontSize = 12
annotationCharStyle.FontName = "Segoe UI"
annotationCharStyle.ForeColor = Color.Gray
document.EndUpdate()

'Apply the created style to the first paragraph of the annotation
document.Paragraphs(1).Style = annotationStyle

'Apply the linked style to the range of the annotation's second paragraph
Dim annotationProperties As CharacterProperties = document.BeginUpdateCharacters(document.Paragraphs(2).Range)
annotationProperties.Style = annotationCharStyle
document.EndUpdateCharacters(annotationProperties)

The image below illustrates the result of the code execution.

See Also

LinkedStyle

ParagraphStyle Interface

ParagraphStyle Members

DevExpress.XtraRichEdit.API.Native Namespace