Click here to Skip to main content
11,717,541 members (77,950 online)
Rate this: bad
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 2: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 at 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
0 Sergey Alexandrovich Kryukov 689
1 OriginalGriff 255
2 F-ES Sitecore 210
3 Jochen Arndt 120
4 Maciej Los 120
0 Sergey Alexandrovich Kryukov 1,494
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2015
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