Skip to main content

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.v24.1.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public void CopyFrom(
    TextSpan textSpan
)

Parameters

Name Type Description
textSpan TextSpan

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:

<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