Skip to main content
All docs
V24.1

Table.ChangePropertiesAsync(Action<TableProperties>, CancellationToken) Method

Sets table properties.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<bool> ChangePropertiesAsync(
    Action<TableProperties> modifier,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
modifier Action<TableProperties>

A delegate method that configures table properties.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<Boolean>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is true if the operation is successful; otherwise, false.

Remarks

Pass a TableProperties object to the ChangePropertiesAsync method to customize table appearance. Most appearance settings can apply to both the table and a cell. Cell settings have priority over table settings.

Read Tutorial: Tables

The following example creates a table and customizes its appearance:

<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 = firstTable.Rows.Count - 1; i >= 0 ; i--)
                for (int j = firstTable.Rows[i].Cells.Count - 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.AutoFit = false;
                properties.BackgroundColor = System.Drawing.Color.AliceBlue;
                properties.Borders.InsideHorizontal.Style = BorderLineStyle.None;
                properties.CellMargins.Top = 50;
                properties.ContentHorizontalAlignment = HorizontalAlignment.Center;
                properties.ContentVerticalAlignment = VerticalAlignment.Center;
                properties.StyleName = TableStyleName.GridTable4Accent4;
                properties.TableStyleOptions = properties.TableStyleOptions | TableStyleOptions.BandedRows;
                properties.Width = new TableWidth(TableWidthType.Percent, 100);
            });
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also