Click here to Skip to main content
12,701,539 members (33,967 online)
Rate this:
Please Sign up or sign in to vote.
See more: WPF printing

I have a requirement to print a customized control which is used in a page with header and footer. When I tried to add the customized control as a visual to flow document, if is giving the error as the following:

Specified Visual is already a child of another Visual or the root of a CompositionTarget.

Please help me.

Posted 17-Sep-12 3:40am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This problem will raise because of you are using the same viewport twice or more than once. if the situation is like that first you should clear the viewport by calling the method "clearViewport()",what you are loading then check whether it is null or not.
if the viewport is null then add the childrens to that viewport else return.
this is the method for clearing the viewport.
private void ClearViewPort()
ModelVisual3D viewPortChildLocal;
for (int i = viewport.Children.Count - 1; i >= 0; i--)
viewPortChildLocal = (ModelVisual3D)viewport.Children[i];
if (viewPortChildLocal.Content is DirectionalLight == false)
for checking the viewport if it is null or not

ModelVisual3D visual = new ModelVisual3D();

ClearViewPort(); // first clear
if (visual != null) // and need to check if it is null or not
Sivakrishna Reddy 15-Nov-12 7:09am
Thanks for the Reply..!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100