3
I am trying the following code to replace the text in the question situation, where rtb is the richtextbox
, .Document is the flowdocument
. The text is exchanged 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 on how to do this?
@mgibsonbr Windows Presentation Foundation.
– Leonel Sanches da Silva
I managed to do what I needed after breaking the face a lot, created a function for the search and then added in the function that called replace using the created references. I just don’t know how to post here, the code is too big
– Rafael Perracini
Can you please answer your own question with the solution for the benefit of the community?
– Leonel Sanches da Silva