Back to Devexpress

TableProperties.ContentHorizontalAlignment Property

blazor-devexpress-dot-blazor-dot-richedit-dot-tableproperties.md

latest4.9 KB
Original Source

TableProperties.ContentHorizontalAlignment Property

Specifies the horizontal alignment of content in table cells.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public HorizontalAlignment ContentHorizontalAlignment { get; set; }

Property Value

TypeDescription
HorizontalAlignment

An enumeration value.

|

Available values:

NameDescription
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:

TableThe 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 CellThe 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:

razor
<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

Tables in Blazor Rich Text Editor

TableProperties Class

TableProperties Members

DevExpress.Blazor.RichEdit Namespace