Skip to main content
All docs
V24.1

Table.CellMargins Property

Returns margin settings of all cells in the table.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public IMargins CellMargins { get; }

Property Value

Type Description
IMargins

An object that contains margin settings.

Remarks

The Rich Text Editor component allows you to specify margin settings for the following table elements:

Table
The CellMargins property allows you to obtain margin settings common to all cells. Call the ChangePropertiesAsync method and specify the TableProperties.CellMargins setting to customize margins of all cells simultaneously.
Table Cell
A cell stores its margin settings in the Margins property. Call the ChangePropertiesAsync method and specify the TableCellProperties.BackgroundColor setting to customize cell margins.

Note

A cell’s Margins property takes priority over the table’s CellMargins property.

The following example configures cell margins:

Cell Margins

<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.CellMargins.Top = 0;
                properties.CellMargins.Bottom = 0;
                properties.Width = new TableWidth(TableWidthType.Percent, 100);
            });
            foreach (TableCell cell in firstTable.Rows[0].Cells)
                await cell.ChangePropertiesAsync(properties => {
                    properties.Margins.Top = 100;
                    properties.Margins.Bottom = 100;
                });
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also