I'm trying the following code to replace the text in the question situation, where rtb is richtextbox
, .Document is flowdocument
. The text is changed in Run (r), but when I open the document the exchange was not made.
foreach (Block oBlock in rtb.Document.Blocks)
{
Paragraph oParagraph = oBlock as Paragraph;
if (oParagraph != null)
{
foreach (Inline il in oParagraph.Inlines)
{
if (il is Figure)
{
foreach (Block bl in ((System.Windows.Documents.AnchoredBlock)(il)).Blocks)
{
if (bl is Table)
{
Table t = bl as Table;
foreach (Block cellBlock in t.RowGroups[reportReference.RowGroup].Rows[reportReference.Line].Cells[reportReference.Column].Blocks)
{
Paragraph p = cellBlock as Paragraph;
if (p != null)
{
Run r = p.Inlines.FirstInline as Run;
if (r != null && r.Text.Contains(searchEntry))
{
r.ContentStart.DeleteTextInRun(searchEntry.Length + 1);
r.ContentStart.InsertTextInRun(Constants.TagId + newName);;
}
}
}
}
}
}
}
}
}
Any suggestions how to do this?