Back to Devexpress

CharacterStyle.LinkedStyle Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-characterstyle-5bc3d722.md

latest8.3 KB
Original Source

CharacterStyle.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
ParagraphStyle LinkedStyle { get; set; }
vb
Property LinkedStyle As ParagraphStyle

Property Value

TypeDescription
ParagraphStyle

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.

The following code snippets (auto-collected from DevExpress Examples) contain references to the LinkedStyle property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-rich-edit-text-formatting/CS/Text Formatting Example/Form1.cs#L147

csharp
document.CharacterStyles.Add(annotationCharStyle);
annotationCharStyle.LinkedStyle = annotationStyle;

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Styles.cs#L73

csharp
document.CharacterStyles.Add(lcstyle);
lcstyle.LinkedStyle = lstyle;

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/StylesActions.cs#L71

csharp
document.CharacterStyles.Add(lcstyle);
lcstyle.LinkedStyle = lstyle;

winforms-rich-edit-text-formatting/VB/Text Formatting Example/Form1.vb#L139

vb
document.CharacterStyles.Add(annotationCharStyle)
annotationCharStyle.LinkedStyle = annotationStyle

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Styles.vb#L66

vb
document.CharacterStyles.Add(lcstyle)
lcstyle.LinkedStyle = lstyle
lcstyle.ForeColor = System.Drawing.Color.DarkGreen

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/StylesActions.vb#L62

vb
document.CharacterStyles.Add(lcstyle)
lcstyle.LinkedStyle = lstyle

word-document-api-examples/VB/CodeExamples/StylesActions.vb#L105

vb
' Set the created character style to the created paragraph style.
lcstyle.LinkedStyle = lstyle
' Specify the created character style's settings.

See Also

LinkedStyle

CharacterStyle Interface

CharacterStyle Members

DevExpress.XtraRichEdit.API.Native Namespace