Skip to main content
All docs
V24.1

TableCellProperties.ContentHorizontalAlignment Property

Specifies the horizontal alignment of content in the cell.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public HorizontalAlignment ContentHorizontalAlignment { get; set; }

Property Value

Type Description
HorizontalAlignment

An enumeration value.

Available values:

Name Description
Center

Center alignment.

Left

Left alignment.

Right

Right alignment.

Remarks

The Rich Text Editor component allows you to specify a content horizontal alignment for the following elements:

Table
The ContentHorizontalAlignment property stores the horizontal alignment of content in table cells. Call the ChangePropertiesAsync method and specify the TableProperties.ContentHorizontalAlignment setting to horizontally align content in all cells simultaneously.
Table Cell
The ContentHorizontalAlignment property stores the horizontal alignment of cell content. Call the ChangePropertiesAsync method and specify the TableCellProperties.ContentHorizontalAlignment setting to horizontally align cell content.

Note

A cell’s ContentHorizontalAlignment property takes priority over the table’s ContentHorizontalAlignment property.

The following example aligns content in table cells:

Align Cell Content

<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.ContentHorizontalAlignment = HorizontalAlignment.Left;
                properties.ContentVerticalAlignment = VerticalAlignment.Top;
                properties.Width = new TableWidth(TableWidthType.Percent, 100);
            });
            foreach (TableRow row in firstTable.Rows)
                await row.ChangePropertiesAsync(properties => {
                    properties.Height = new TableRowHeight(TableRowHeightType.Exact, 400);
                });
            foreach (TableCell cell in firstTable.Rows[0].Cells)
                await cell.ChangePropertiesAsync(properties => {
                    properties.ContentHorizontalAlignment = HorizontalAlignment.Center;
                    properties.ContentVerticalAlignment = VerticalAlignment.Center;
                });
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also