Table Authoring Service
The Content.TableAuthoringService property on WpfHtmlEditor returns an ITableAuthoringService instance. It exposes every table-level command -- insert and delete rows and columns, merge selected cells, manage the zero-border guideline overlay, and access the lower-level ITableManipulator. Drive the service from a custom ribbon, a key binding, or an automation routine.
Namespace: SpiceLogic.HtmlEditor.Abstractions.Services.ElementAuthoring
Assembly: SpiceLogic.HtmlEditor.Abstractions.dll
Accessor: MyEditor.Content.TableAuthoringService
The service implements IDisposable; the editor owns its lifetime, so customer code never needs to call Dispose directly.
InsertColumn(InsertPositions position)
Inserts a new empty column adjacent to the column that currently contains the caret.
Syntax
void InsertColumn(InsertPositions position);Parameters
| Name | Type | Description |
|---|---|---|
| position | InsertPositions | InsertPositions.Before inserts the new column to the left of the caret column; InsertPositions.After inserts it to the right. |
Remarks
The caret must be inside a table cell; otherwise the call is a no-op.
Example
using SpiceLogic.HtmlEditor.Abstractions;
using SpiceLogic.HtmlEditor.Abstractions.Services.ElementAuthoring;
ITableAuthoringService tables = MyEditor.Content.TableAuthoringService;
tables.InsertColumn(InsertPositions.Before);Imports SpiceLogic.HtmlEditor.Abstractions
Imports SpiceLogic.HtmlEditor.Abstractions.Services.ElementAuthoring
Dim tables As ITableAuthoringService = MyEditor.Content.TableAuthoringService
tables.InsertColumn(InsertPositions.Before)DeleteColumn()
Removes the column that currently contains the caret. If the deleted column was the last column in the table, the table itself is removed.
Syntax
void DeleteColumn();Example
private void DeleteColumn_Click(object sender, RoutedEventArgs e)
{
MyEditor.Content.TableAuthoringService.DeleteColumn();
}Private Sub DeleteColumn_Click(sender As Object, e As RoutedEventArgs)
MyEditor.Content.TableAuthoringService.DeleteColumn()
End SubInsertRow(InsertPositions position)
Inserts a new empty row adjacent to the row that currently contains the caret.
Syntax
void InsertRow(InsertPositions position);Parameters
| Name | Type | Description |
|---|---|---|
| position | InsertPositions | InsertPositions.Before inserts the row above the caret row; InsertPositions.After inserts it below. |
Example
MyEditor.Content.TableAuthoringService.InsertRow(InsertPositions.After);DeleteRow()
Removes the row that currently contains the caret. If the deleted row was the last row, the table itself is removed.
Syntax
void DeleteRow();Example
if (MessageBox.Show("Delete current row?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
MyEditor.Content.TableAuthoringService.DeleteRow();
}If MessageBox.Show("Delete current row?", "Confirm", MessageBoxButton.YesNo) Is MessageBoxResult.Yes Then
MyEditor.Content.TableAuthoringService.DeleteRow()
End IfMergeSelectedCells()
Merges the cells in the current selection into a single cell. The merge uses colspan / rowspan attributes on the surviving cell and discards the others.
Syntax
void MergeSelectedCells();Remarks
Call CanMergeCells() first. The merge is disabled when EnableTableCellMerging is false.
Example
var tables = MyEditor.Content.TableAuthoringService;
if (tables.CanMergeCells())
{
tables.MergeSelectedCells();
}Dim tables = MyEditor.Content.TableAuthoringService
If tables.CanMergeCells() Then
tables.MergeSelectedCells()
End IfShowGuidelinesForTablesWithZeroBorder(bool inBackground = false)
Applies a dotted CSS outline to every table whose border attribute is 0 so authors can still see cell boundaries while editing. The outline is visual only and is stripped before the HTML is returned to the customer.
Syntax
void ShowGuidelinesForTablesWithZeroBorder(bool inBackground = false);Parameters
| Name | Type | Description |
|---|---|---|
| inBackground | bool | When true, the DOM walk skips forcing layout updates -- pass true from background-paint code paths to avoid flicker. Defaults to false. |
Example
private void ToggleGuides_Click(object sender, RoutedEventArgs e)
{
MyEditor.Content.TableAuthoringService.ShowGuidelinesForTablesWithZeroBorder();
}Private Sub ToggleGuides_Click(sender As Object, e As RoutedEventArgs)
MyEditor.Content.TableAuthoringService.ShowGuidelinesForTablesWithZeroBorder()
End SubHideGuidelinesOfTablesWithZeroBorder(bool inBackground = false)
Removes the dotted overlay added by ShowGuidelinesForTablesWithZeroBorder.
Syntax
void HideGuidelinesOfTablesWithZeroBorder(bool inBackground = false);Parameters
| Name | Type | Description |
|---|---|---|
| inBackground | bool | Pass the same value used in the matching ShowGuidelinesForTablesWithZeroBorder call. |
Example
MyEditor.Content.TableAuthoringService
.HideGuidelinesOfTablesWithZeroBorder();IsTableBorderZero(IHTMLElement tableElement)
Returns true when the supplied table element has a border attribute of 0 (and is therefore a candidate for the zero-border guideline overlay).
Syntax
bool IsTableBorderZero(IHTMLElement tableElement);Parameters
| Name | Type | Description |
|---|---|---|
| tableElement | mshtml.IHTMLElement | The HTML <table> element to inspect. |
Returns
true if the element's border attribute is "0" or missing; otherwise false.
Example
using mshtml;
var tables = MyEditor.Content.TableAuthoringService;
IHTMLElement table = MyEditor.StateQuery.GetActiveHtmlElement();
if (table?.tagName == "TABLE" && tables.IsTableBorderZero(table))
{
tables.ShowGuidelinesForTablesWithZeroBorder();
}Imports mshtml
Dim tables = MyEditor.Content.TableAuthoringService
Dim table As IHTMLElement = MyEditor.StateQuery.GetActiveHtmlElement()
If table?.tagName Is "TABLE" AndAlso tables.IsTableBorderZero(table) Then
tables.ShowGuidelinesForTablesWithZeroBorder()
End IfCanMergeCells()
Reports whether the current cell selection can be merged.
Syntax
bool CanMergeCells();Returns
true if at least two adjacent table cells are selected and cell merging is enabled; otherwise false. Use this to drive the enabled state of a custom Merge-Cells command.
Example
MyEditor.SelectionChanged += (s, e) =>
{
MergeCellsButton.IsEnabled =
MyEditor.Content.TableAuthoringService.CanMergeCells();
};GetTableManipulator()
Returns the lower-level ITableManipulator the service uses internally. Use this when you need direct row/column DOM access beyond the high-level methods above.
Syntax
ITableManipulator GetTableManipulator();Returns
The shared ITableManipulator instance, or null when the caret is not inside a table.
Example
var manip = MyEditor.Content.TableAuthoringService.GetTableManipulator();
if (manip != null && manip.CanMerge())
{
Debug.WriteLine("Selection can be merged.");
}Dim manip = MyEditor.Content.TableAuthoringService.GetTableManipulator()
If manip IsNot Nothing AndAlso manip.CanMerge() Then
Debug.WriteLine("Selection can be merged.")
End IfResetTableManipulator()
Discards the cached ITableManipulator so that the next call to GetTableManipulator re-creates one against the current document. Call this after replacing the document HTML wholesale.
Syntax
void ResetTableManipulator();Example
MyEditor.Content.LoadBodyHtml("<table><tr><td>Z</td></tr></table>");
MyEditor.Content.TableAuthoringService.ResetTableManipulator();SelectedCellBackgroundColor Property
Gets or sets the background color used to highlight cells that are part of the current multi-cell selection (the visual feedback the editor draws while the user drags across cells).
Syntax
Color SelectedCellBackgroundColor { get; set; }Property Value
A System.Drawing.Color. The default is a light blue chosen for legibility on most page backgrounds.
Example
using System.Drawing;
MyEditor.Content.TableAuthoringService.SelectedCellBackgroundColor = Color.FromArgb(120, 0, 122, 204); // brand-blue overlay
Imports System.Drawing
MyEditor.Content.TableAuthoringService.SelectedCellBackgroundColor = Color.FromArgb(120, 0, 122, 204) ' brand-blue overlayEnableTableCellMerging Property
Gets or sets whether the service permits cell merging. When false, MergeSelectedCells and CanMergeCells are inert.
Syntax
bool EnableTableCellMerging { get; set; }Property Value
true to allow cell merging; false to forbid it. The editor mirrors this from Options.EnableTableCellMerge at startup.
Example
// Make cell-merging available only in expert mode.
MyEditor.Content.TableAuthoringService.EnableTableCellMerging = appPrefs.ExpertMode;