Unplanned
Last Updated: 21 Dec 2017 11:38 by ADMIN
ADMIN
Tanya
Created on: 20 Dec 2017 15:23
Category: RichTextBox
Type: Bug Report
0
RichTextBox: Table and cell local properties are not reset when applying table style
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;
        }
    }
}
2 comments
ADMIN
Tanya
Posted on: 21 Dec 2017 11:35
Hi Renan,

Thank you for your feedback.

The Background of the cells depends on the conditional styles which a Table style could define. I am updating the description of the item and the proposed workaround to reflect the background of the cells as well.

Regards,
Tanya
Renan
Posted on: 20 Dec 2017 18:50
Hi Tanya, 
It worked fine for borders. I'm trying to do the same with background but it's not working. The background color coming from style.TableCellProperties.Background is always white.
StyleDefinition style = this.Document.StyleRepository.GetValueOrNull(e.CommandParameter.ToString());

                    if (style.Type == StyleType.Table)
                    {
                        Table table = this.Document.CaretPosition.GetCurrentTableBox().AssociatedTable;
                        
                        table.Borders = new TableBorders(style.TableProperties.Borders);
                        
                        foreach (var cell in table.EnumerateChildrenOfType<TableCell>())
                        {
                            cell.Borders = new TableCellBorders(style.TableCellProperties.Borders);
                            cell.Background = style.TableCellProperties.Background;

                        }
                        
                    }