Back to Devexpress

CharacterProperties.CopyFrom(TextSpan) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-characterproperties-dot-copyfrom-x28-devexpress-dot-blazor-dot-richedit-dot-textspan-x29.md

latest2.9 KB
Original Source

CharacterProperties.CopyFrom(TextSpan) Method

Duplicates properties of the specified text span into the current CharacterProperties class instance.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public void CopyFrom(
    TextSpan textSpan
)

Parameters

NameTypeDescription
textSpanTextSpan

The source text span.

|

Remarks

The CopyFrom method copies properties of the specified TextSpan object to the current CharacterProperties class instance.

Send the result CharacterProperties object to the ChangePropertiesAsync method as a parameter to copy all properties of a text span to another span.

The following example copies character properties between two text spans:

razor
<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;

    protected override async Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender)
            try {
                await InitializeDocument();
            }
            catch (TaskCanceledException) { }
        await base.OnAfterRenderAsync(firstRender);
    }

    async Task InitializeDocument() {
    /* 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 canceled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            TextSpan characters = await documentAPI.AddTextAsync("New Text");
            IReadOnlyList<Paragraph> paragraphs = await documentAPI.Paragraphs.GetAllAsync();
            foreach (Paragraph p in paragraphs) {
                TextSpan currentCharacters = await documentAPI.GetTextSpanAsync(p.Interval);
                await currentCharacters.ChangePropertiesAsync(properties => {
                    properties.CopyFrom(characters);
                });
            }
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

See Also

CharacterProperties Class

CharacterProperties Members

DevExpress.Blazor.RichEdit Namespace