Skip to main content
All docs
V25.1
  • TableCellProperties.BackgroundColor Property

    Specifies the cell’s background color.

    Namespace: DevExpress.Blazor.RichEdit

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

    NuGet Package: DevExpress.Blazor.RichEdit

    Declaration

    public Color BackgroundColor { get; set; }

    Property Value

    Type Description
    Color

    The cell’s background color.

    Remarks

    The Rich Text Editor component allows you to specify a background color for the following table elements:

    Table
    The BackgroundColor property allows you to identify the table’s background color. Call the ChangePropertiesAsync method and specify the TableProperties.BackgroundColor setting to change the table’s background color.
    Table Cell
    The BackgroundColor property allows you to obtain the cell’s background color. Call the ChangePropertiesAsync method and specify the TableCellProperties.BackgroundColor setting to change the cell’s background color.

    Note

    A cell’s background overlaps the table’s background.

    The following example applies different background colors to odd and even table rows:

    Add Shading

    <DxRichEdit @ref="richEdit" />
    
    @code {
        DxRichEdit richEdit;
        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 {
                var columnCount = 4;
                var rowCount = 5;
                richEdit.DocumentAPI.BeginUpdate();
                // Creates a table
                Table firstTable = await richEdit.DocumentAPI.Tables.CreateAsync(0, columnCount, rowCount);
                for (int i = rowCount-1; i >=0 ; i--)
                    for (int j = columnCount-1; j >=0 ; j--) {
                        var cellPosition = firstTable.Rows[i].Cells[j].Interval.Start;
                        await richEdit.DocumentAPI.AddTextAsync(cellPosition, "sample text");
                    }
                // Customizes the table
                await firstTable.ChangePropertiesAsync(properties => {
                    properties.BackgroundColor = System.Drawing.Color.LightBlue;
                    properties.Width = new TableWidth(TableWidthType.Percent, 100);
                });
                foreach (TableRow row in firstTable.Rows)
                    foreach (TableCell cell in row.Cells)
                        if (cell.ParentRow.Index % 2 == 0)
                            await cell.ChangePropertiesAsync(properties => {
                                properties.BackgroundColor = System.Drawing.Color.AliceBlue;
                            });
                richEdit.DocumentAPI.EndUpdate();
            }
            catch (OperationCanceledException e) {
                Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
            }
        }
    }
    
    See Also