When I create a table with LayoutMode = TableLayoutMode.Fixed, multiple columns and different size TableCells, the cells in the second row and onwards have incorrect widths.
When running the code below (see also the attached screenshot):
When running the code below (see also the attached screenshot):
- the widths of the cells in the first row are correct
- the first cell in the second and third row are too wide
- the second and fourth cell in the second and third row should be the same width, but they are not
Am I doing something wrong? Should I take some margin or border width into account when working with fixed with TableCells?
I'm using version 2012.3.1129.40
using
System.Collections.Generic;
using
System.Windows.Media;
using
Telerik.Windows.Documents.Model;
namespace
RadDocumentTableTest
{
public
partial
class
MainWindow
{
public
MainWindow()
{
InitializeComponent();
var document =
new
RadDocument();
var section =
new
Section();
section.Blocks.Add(
new
Paragraph());
var table =
new
Table
{
LayoutMode = TableLayoutMode.Fixed,
Style = document.StyleRepository[
"TableGrid"
],
PreferredWidth =
new
TableWidthUnit(618)
};
table.Rows.AddRange(CreateRows());
section.Blocks.Add(table);
document.Sections.Add(section);
RichTextBox.Document = document;
}
private
static
TableCell CreateTableCell(
int
colSpan,
double
width,
string
text)
{
var cell =
new
TableCell
{
ColumnSpan = colSpan,
PreferredWidth =
new
TableWidthUnit(TableWidthUnitType.Fixed, width),
};
var par =
new
Paragraph();
var span =
new
Span
{
Text = text,
FontFamily =
new
FontFamily(
"Calibri"
),
FontSize = 15
};
par.Inlines.Add(span);
cell.Blocks.Add(par);
return
cell;
}
private
static
IEnumerable<TableRow> CreateRows()
{
var rows =
new
List<TableRow>();
var row1 =
new
TableRow();
row1.Cells.Add(CreateTableCell(1, 55,
"r1c1:cs1:w55"
));
row1.Cells.Add(CreateTableCell(2, 125,
"r1c2:cs2:w125"
));
row1.Cells.Add(CreateTableCell(1, 90,
"r1c3:cs1:w90"
));
row1.Cells.Add(CreateTableCell(3, 348,
"r1c4:cs3:w348"
));
rows.Add(row1);
var row2 =
new
TableRow();
row2.Cells.Add(CreateTableCell(2, 90,
"r2c1:cs2:w90"
));
row2.Cells.Add(CreateTableCell(3, 219,
"r2c2:cs3:w219"
));
row2.Cells.Add(CreateTableCell(1, 90,
"r2c3:cs1:w90"
));
row2.Cells.Add(CreateTableCell(1, 219,
"r2c4:cs1:w219"
));
rows.Add(row2);
var row3 =
new
TableRow();
row3.Cells.Add(CreateTableCell(2, 90,
"r3c1:cs2:w90"
));
row3.Cells.Add(CreateTableCell(3, 219,
"r3c2:cs3:w219"
));
row3.Cells.Add(CreateTableCell(1, 90,
"r3c3:cs1:w90"
));
row3.Cells.Add(CreateTableCell(1, 219,
"r3c4:cs1:w219"
));
rows.Add(row3);
return
rows;
}
}
}