blazor-devexpress-dot-blazor-dot-richedit-dot-table.md
Returns the horizontal alignment of content in table cells.
Namespace : DevExpress.Blazor.RichEdit
Assembly : DevExpress.Blazor.RichEdit.v25.2.dll
NuGet Package : DevExpress.Blazor.RichEdit
public HorizontalAlignment ContentHorizontalAlignment { get; }
| Type | Description |
|---|---|
| HorizontalAlignment |
An enumeration value.
|
Available values:
| Name | Description |
|---|---|
| Center |
Center alignment.
| | Left |
Left alignment.
| | Right |
Right alignment.
|
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:
<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