Click here to Skip to main content
12,067,351 members (56,619 online)
Rate this:
 
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 3: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 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
Web03 | 2.8.160208.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2016
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