When applying a table style, the previously applied local properties to a table or cell should be cleared and the ones defined by the style should be used.
Workaround: Create a new Table and apply the style to it; then copy the properties to the existing table in the document
private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
if (e.Command is ChangeStyleNameCommand && this.radRichTextBox.Document.CaretPosition.IsPositionInsideTable)
{
StyleDefinition style = this.radRichTextBox.Document.StyleRepository.GetValueOrNull(e.CommandParameter.ToString());
if (style.Type == StyleType.Table)
{
Table currentTable = this.radRichTextBox.Document.CaretPosition.GetCurrentTableBox().AssociatedTable;
currentTable.Borders = new TableBorders(style.TableProperties.Borders);
Table tableWithStyle = new Table(currentTable.Rows.Count, currentTable.Rows.First.Cells.Count);
tableWithStyle.Style = this.radRichTextBox.Document.StyleRepository.GetValueOrNull(e.CommandParameter.ToString());
for (int rowIndex = 0; rowIndex < currentTable.Rows.Count; rowIndex++)
{
for (int columnIndex = 0; columnIndex < currentTable.Rows.First.Cells.Count; columnIndex++)
{
TableCell cell = currentTable.Rows.Skip(rowIndex).First().Cells.Skip(columnIndex).First();
TableCell cellWithStyle = tableWithStyle.Rows.Skip(rowIndex).First().Cells.Skip(columnIndex).First();
cell.Background = cellWithStyle.Background;
cell.Borders = cellWithStyle.Borders;
}
}
this.radRichTextBox.UpdateEditorLayout();
e.Cancel = true;
}
}
}