Click here to Skip to main content
15,879,071 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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

1 solution

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;
}
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900