Hi everyone,
I have a problem: I use a RadRichTextBox and in code(in runtime) by button click event I insert a Table
with InlineUIContainers in each cell - everything is OK, but when I drag it using a Table aborner by mouse(a small cross in the left top of table) then all InlineUIContainers are removed!!! If cell contains just a Paragraph and span inside it - everithyng is OK, but
I need to use an InlineUIContainers with a Border and TextBlock element as implemented below in method
I have a problem: I use a RadRichTextBox and in code(in runtime) by button click event I insert a Table
with InlineUIContainers in each cell - everything is OK, but when I drag it using a Table aborner by mouse(a small cross in the left top of table) then all InlineUIContainers are removed!!! If cell contains just a Paragraph and span inside it - everithyng is OK, but
I need to use an InlineUIContainers with a Border and TextBlock element as implemented below in method
InitDataCell(...)
private
void
InsertDynamicTable(DynamicTableViewModel dynamicTableViewModel)
{
var table =
new
Table();
TableRow r1 =
new
TableRow();
r1.Cells.Add(
new
TableCell());
r1.Cells.Add(
new
TableCell());
r1.Cells.Add(
new
TableCell());
table.Rows.Add(r1);
TableRow r2 =
new
TableRow();
r2.Cells.Add(
new
TableCell());
r2.Cells.Add(
new
TableCell());
r2.Cells.Add(
new
TableCell());
table.Rows.Add(r2);
TableRow r3 =
new
TableRow();
r3.Cells.Add(
new
TableCell());
r3.Cells.Add(
new
TableCell());
r3.Cells.Add(
new
TableCell());
table.Rows.Add(r3);
table.Tag = dynamicTableViewModel.ID.ToString();
table.Borders =
new
TableBorders(
new
Border(dynamicTableViewModel.BorderThikness, BorderStyle.Single, dynamicTableViewModel.BorderColor));
table.PreferredWidth =
new
TableWidthUnit(TableWidthUnitType.Fixed, dynamicTableViewModel.Width);
table.LayoutMode = TableLayoutMode.Fixed;
TableRow dataRow = table.Rows.ToArray().ToList()[1];
List<TableCell> dataCells = dataRow.Cells.ToArray().ToList();
List<
double
> dataCellHeights =
new
List<
double
>();
for
(
int
i = 0; i < dynamicTableViewModel.DynamicColumns.Count; i++)
{
TableCell dataCell = dataCells[i];
InitHeaderCell(headerCell, dynamicTableViewModel.DynamicColumns[i]);
//Initialize existant TableCell
double
dataCellHeight = InitDataCell(dataCell, dynamicTableViewModel.DynamicColumns[i]);
dataCellHeights.Add(dataCellHeight);
}
UpdateRowHeight(dataRow, dataCellHeights);
this
.richEditor.InsertTable(table);
this
.richEditor.UpdateEditorLayout();
this
.richEditor.Document.UpdateAllFields();
this
.richEditor.Document.UpdateLayout();
}
private
double
InitDataCell(TableCell dataCell, DynamicColumnViewModel columnVm)
{
double
cellHeight = 0;
dataCell.PreferredWidth =
new
TableWidthUnit(TableWidthUnitType.Fixed, columnVm.Width);
dataCell.TextAlignment = RadTextAlignment.Left;
dataCell.VerticalAlignment = RadVerticalAlignment.Center;
var paragraph =
new
Paragraph();
paragraph.TextAlignment = RadTextAlignment.Right;
dataCell.Blocks.Add(paragraph);
dataCell.Background = columnVm.DynamicCellData.Background;
Grid grid =
new
Grid();
var tb =
new
TextBlock
{
Text = columnVm.DbColumnName,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
Tag = columnVm.DbColumnName,
FontSize = columnVm.DynamicCellData.FontSize,
Background =
new
SolidColorBrush(columnVm.DynamicCellData.Background),
Foreground =
new
SolidColorBrush(columnVm.DynamicCellData.Foreground),
FontFamily = columnVm.DynamicCellData.FontFamily,
FontWeight = columnVm.DynamicCellData.FontWeight,
FontStyle = columnVm.DynamicCellData.FontStyle,
TextDecorations = columnVm.DynamicCellData.TextDecoration
};
tb.VerticalAlignment = VerticalAlignment.Bottom;
tb.HorizontalAlignment = HorizontalAlignment.Right;
System.Windows.Controls.Border border =
new
System.Windows.Controls.Border();
border.BorderThickness =
new
Thickness(0);
border.BorderBrush = Brushes.Transparent;
border.Background =
new
SolidColorBrush(columnVm.DynamicCellData.Background);
border.VerticalAlignment = VerticalAlignment.Center;
border.HorizontalAlignment = HorizontalAlignment.Center;
border.Child = tb;
border.Measure(
new
Size(Double.PositiveInfinity, Double.PositiveInfinity));
Size s =
new
Size(border.DesiredSize.Width + 1, tb.DesiredSize.Height - 1);
var uic =
new
InlineUIContainer(border, s);
paragraph.Inlines.Add(uic);
cellHeight = uic.Height + 5;
return
cellHeight;
}