I have two RichTextboxes on my page. I am using them as a Book interface. There are two buttons to turn forward and back.
Traversing through the pages forward works fine. But once I hit back, VS2010 shoots an exception
Element is already the child of another element.
This is for the paragraph I am adding in the RichTextbox. This happen even though I am clearing both the RichTextboxes before flooding them with new data.
My code below. What am I missing?
TxtBlobLeft.Blocks.Clear();
TxtBlobRight.Blocks.Clear();
foreach (Paragraph item in pagesStack[count].paras)
{
TxtBlobLeft.Blocks.Add(item); //Throws exception here
}
foreach (Paragraph item in pagesStack[count + 1].paras)
{
TxtBlobRight.Blocks.Add(item);
}
Note: pagesStack is a custom Object with Paras (i.e List) as a property.
Seems like Clear doesn’t remove the parent reference of Paragraphs to the RTB. I created a new method for Clear using the following forach loop to remove all items.
paras is my List of Paragraphs which I had added to the RTB previously.