Hello!
I have a problem with changing RadDocument in code: I set Background color for tables and ForeColor for spans inside table cells when I prepare RadDocument in code, then I change ForeColor and Background on button click, but the Document updates only after scrolling. Where is my mistake?
Here is my code:
I have a problem with changing RadDocument in code: I set Background color for tables and ForeColor for spans inside table cells when I prepare RadDocument in code, then I change ForeColor and Background on button click, but the Document updates only after scrolling. Where is my mistake?
Here is my code:
public partial class TestWindow : UserControl
{
public TestWindow()
{
InitializeComponent();
}
public RadDocument BaseRadDocument;
public void createRadDocument()
{
BaseRadDocument = new RadDocument();
BaseRadDocument.LayoutMode = DocumentLayoutMode.Flow;
BaseRadDocument.ParagraphDefaultSpacingAfter = 0;
BaseRadDocument.PageViewMargin = new SizeF(0, 0);
BaseRadDocument.SectionDefaultPageMargin = new Padding(0);
Section section = new Section();
CreateSection(0, section);
BaseRadDocument.Sections.Add(section);
rich.Document = BaseRadDocument;
}
public void CreateSection(int level, Section section)
{
for (int i = 0; i < 15; i++)
{
createDocElementsForNewItem(i, section);
}
}
private void createDocElementsForNewItem(int level, Section section)
{
int indent = 20 * level;
var cell_11 = new TableCell();
cell_11.PreferredWidth = new TableWidthUnit(80 + indent);
var cell_12 = new TableCell();
Paragraph paragraph_111 = new Paragraph();
paragraph_111.LeftIndent = indent;
paragraph_111.SpacingAfter = 0;
paragraph_111.SpacingBefore = 0;
paragraph_111.TextAlignment = RadTextAlignment.Right;
Span date = new Span(String.Format("{0} ", DateTime.UtcNow.ToShortDateString()));
date.FontSize = 12;
date.ForeColor = new Color() { A = 0xff, B = 0x68, G = 0x68, R = 0x68 };
date.FontFamily = new FontFamily("Calibri");
paragraph_111.Inlines.Add(date);
Paragraph paragraph_112 = new Paragraph();
paragraph_112.LeftIndent = indent;
paragraph_112.SpacingAfter = 0;
paragraph_112.SpacingBefore = 0;
paragraph_112.TextAlignment = RadTextAlignment.Right;
Span time = new Span(String.Format("{0} ", DateTime.UtcNow.ToLongTimeString()));
time.FontSize = 12;
time.ForeColor = new Color() { A = 0xff, B = 0x68, G = 0x68, R = 0x68 };
time.FontFamily = new FontFamily("Calibri");
paragraph_112.Inlines.Add(time);
paragraph_112.LeftIndent = indent;
for (int j = 0; j < 5; j++)
{
var span = new Span(String.Format("Текст {0}", j));
var par = new Paragraph();
span.ForeColor = new Color() { A = 0xff, B = 0x00, G = 0x52, R = 0xC6 };
par.Inlines.Add(span);
cell_12.Blocks.Add(par);
}
cell_11.Blocks.Add(paragraph_111);
cell_11.Blocks.AddAfter(paragraph_111, paragraph_112);
var row_1 = new TableRow();
row_1.Cells.Add(cell_11);
row_1.Cells.AddAfter(cell_11, cell_12);
Table table = new Table();
table.Background = new Color(){A = 0xFF, R=0xFF, G=0xB9, B=0xB9};
table.Rows.Add(row_1);
section.Blocks.Add(table);
section.Blocks.Add(new Paragraph());
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
createRadDocument();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
foreach (var section in BaseRadDocument.Sections)
foreach (var block in section.Blocks)
{
if (block is Table)
{
var table = block as Table;
table.Background = new Color() { A = 0xFF, R = 0xFC, G = 0xFF, B = 0xC8 };
foreach (var row in table.Rows)
foreach (var cell in row.Cells)
foreach (var item in cell.Blocks)
if (item is Paragraph)
{
foreach (var inline in (item as Paragraph).Inlines)
if (inline is Span)
{
(inline as Span).ForeColor = new Color() { A = 0xFF, R = 0x1F, G = 0x3C, B = 0x6C };
}
}
}
}
BaseRadDocument.UpdateLayout();
}
}