Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF printing
Hello,
 
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.
 
Thanks,
Siva.
Posted 17-Sep-12 2:40am

1 solution

Rate this: bad
good
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)
{
viewport.Children.RemoveAt(i);
}
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
{
viewport.Children.Add(visual);
}
else
{
return;
}
  Permalink  
Comments
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 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


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