Skip to main content

CharacterProperties.ForegroundColor Property

Specifies the font color of characters.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v24.1.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public Color? ForegroundColor { get; set; }

Property Value

Type Description
Nullable<Color>

The font color or null if at least two different characters have different colors.

Remarks

The ForegroundColor property sets a color for the following elements:

The image below demonstrates the ForegroundColor property in action.

Rich Edit - Foreground Color

Use a text span’s ForegroundColor or a table cell’s CharacterProperties.ForegroundColor property to obtain the font color of characters in the span or cell. Call the TextSpan.ChangePropertiesAsync or TableCell.ChangePropertiesAsync method to change the font color of characters.

The following example changes the font color to dark blue for all characters in a text span:

<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");
            await characters.ChangePropertiesAsync(properties => {
                properties.ForegroundColor = System.Drawing.Color.DarkBlue;
            });
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

Implements

See Also