TextSpan Class
A span of document content.
Namespace: DevExpress.Blazor.RichEdit
Assembly: DevExpress.Blazor.RichEdit.v21.1.dll
NuGet Package: DevExpress.Blazor.RichEdit
Declaration
public class TextSpan :
DocumentElementBase,
ICharacterProperties,
ICharacterProperties
Remarks
A TextSpan object contains the following information:
- The textual representation of the span content (Text).
- The span interval in the sub-document (Interval).
- Style and formatting settings of characters in the span (for instance, FontSize, Underline).
Use an instance of the TextSpan class to change character properties in the document. Pass a CharacterProperties object to the ChangePropertiesAsync(Action<CharacterProperties>) method to change properties of the text span’s characters. You can specify character properties manually or use the CopyFrom(TextSpan) method to copy properties from another text span.
Call a GetTextSpanAsync method to get a span contained in the specified sub-document interval.
The code sample below applies bold formatting to characters in the selected intervals.
<DxRichEdit @ref="richEdit" Id="richEdit" @bind-Selection="@selection" />
@code {
DxRichEdit richEdit { get; set; }
Selection selection { get; set; }
@* ... *@
/* Surround the code that contains an asynchronous operation with a try-catch block to handle
the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
try {
IReadOnlyList<Interval> intervals = richEdit.Selection.Intervals;
foreach (Interval interval in intervals) {
TextSpan boldTextSpan = await richEdit.DocumentAPI.GetTextSpanAsync(interval);
await boldTextSpan.ChangePropertiesAsync(properties => {
properties.FontBold = true;
});
}
}
catch (OperationCanceledException e) {
Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
}
}