Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
I've placed some UIElements in a row of the grid at different column positions, now I have a + button if I click on that a new row containing same UIElements should be added below the first row. but it gives me error like "Element is already child of other element".

How can i get rid of this error. I need to add an duplicate copy(new reference) of the control below it in the new row. how can i do it?
Any help would be appreciated....

Thanks,
Gk Prajapati
Posted

1 solution

This is a typical problem of WPF/Silverlight. Nobody can give you a complete ready-to-use solution of this problem, simply because you did not provide any code sample.

However, the idea of solution is pretty simple: you should understand how it works and realize that this is a feature, not a problem. You don't want to "get rid of this error", you want to prevent it. Really, this is a really good feature designed to help developers avoiding doing some stupid things. Any UI element should be added only to one parent. You need to find where you try to add the same reference as a child of some node.

You need to understand child-parent relationships in WPF/Silverlight. For Silverlight, please read this: http://msdn.microsoft.com/en-us/library/cc189034%28v=vs.95%29.aspx[^].

—SA
 
Share this answer
 
Comments
gobind_786 27-Nov-13 15:38pm    
Thanks for reply Sergey, Yes its a good feature and in my case I just want to ignore it. I simply want to Clone UIElement. Is there any way to clone UIElement in Silverlight?
Sergey Alexandrovich Kryukov 27-Nov-13 15:54pm    
"Ignore it"? It's easier to ignore all your code, sorry for being so straight... :-)
You can clone anything easily, I don't even understand why it's a problem. You just cannot violate the rule I just described, period.
Look, someone tried hard to protect you from disaster, but you are kinda trying to say, "I don't want it, I want a disaster"... Come on...
You did not show relevant code sample, you don't want to listen as well. Conclusion? Fine, go on on your own.
—SA

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