0

I am trying to insert dynamic pages inside my fixeddocument in a loop

FixedPage page1 = new FixedPage(); 

but after first page it give error content is already a child of another control. Can you guide me how to add pages to your fixeddocument. How can I make an array of pages?

jophab
  • 5,356
  • 14
  • 41
  • 60
Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57

1 Answers1

0

Make sure that the line FixedPage page1 = new FixedPage(); is executed at the start of every loop, otherwise page1 will always point to the same page and you'll be trying to insert the same page into the document multiple times.

Your code should look like this

while( looping )
{
     FixedPage page1 = new FixedPage(); 
     myFixedDocument.Pages.Add(page1);
}

You should not ever be adding page1 to anything again until the variable has been reassigned to a new FixedPage.

Alain
  • 26,663
  • 20
  • 114
  • 184
  • Can I add a canvas to page as pagecontent. Can it cause an error. Because the error is that the control is child of another parent. Thanks for your help. – Hasan Zubairi Apr 11 '12 at 15:04
  • You cannot add anything that has already been added somewhere else. If you need to add a child to two different parents, you will have to make a copy of it by creating a new one and copying over all the relevant fields from the old one if it doesn't have a copy constructor. – Alain Apr 11 '12 at 15:09
  • Means if I have a Canvas which is a part of a grid then the Canvas cannot be a part of fixedpage. Right? – Hasan Zubairi Apr 11 '12 at 15:29
  • Not all controls impose this restriction but most do. Your best bet is to try it and if it doesn't work, make a copy. – Alain Apr 11 '12 at 15:30