1

Ok, most of you will say "remove your element from its previous parent before adding it to the new panel". I know that, I already applied this many times in other situations, and I can't explain why it doesn't work in this particular case.

Here is an extract of my Debug session and where the exception happened :

enter image description here

As you can see, the parent of my element has no children ! Do you have any advice ? How can I diagnose this problem ? Thanks !

EDIT : I precise that the element has previously been added to a panel used to generate an XPS, and removed after the generation is completed. ==> this is done before we enter in the "AddNewSpecialElement method", but it shouldn't change the problem above.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
JYL
  • 8,228
  • 5
  • 39
  • 63
  • I cant see your debug session? – Whyrusleeping Jul 06 '12 at 14:50
  • The Debug session is an image containing code and pinned variables. It is available here : http://i.stack.imgur.com/Ac7xJ.png – JYL Jul 06 '12 at 15:04
  • There are two trees in WPF: The Logical (code) tree, and the Visual (UI) tree. It sounds like you are removing the object from the visual tree, but not the logical tree. How are you removing your element from the parent? – Rachel Jul 06 '12 at 15:27
  • @Rachel : I don't do anything with the VisualTree, i just add an UIElement to a Panel and remove it once the XPS is generated. – JYL Jul 09 '12 at 07:09

1 Answers1

0

Problem solved. Explanations.

The problem appeared when I follow theses steps :

  1. Draw a list of Visuals on screen (all visuals are placed in a single stackPanel) ==> Ok
  2. Remove the visuals from the stackPanel to use them in my own DocumentPaginator ==> Ok
  3. Print or export them (for exemple using PrintQueue.CreateXpsDocumentWriter().Write(paginator) ). ==> Ok
  4. Once the export is done and the Paginator disposed, add the visuals to the original stackPanel to show them on screen again ==> Ok
  5. Start a new XPS export, repeating from step 2 ==> Exception !

I thought that disposing the Paginator was sufficient. I had no reason to think it was not, because the step 4 worked well. In fact, I had to explicitly remove the visuals from their parent visual inside the Paginator, in a step 3b.

Thanks for reading.

JYL
  • 8,228
  • 5
  • 39
  • 63