Silverlight用户控件中元素已经是其他元素错误的子元素 [英] Element already child of other element error in Silverlight User Control

查看:96
本文介绍了Silverlight用户控件中元素已经是其他元素错误的子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网格的不同列位置放置了一些UIElements,现在我有一个+按钮,如果我点击那个包含相同UIElements的新行应该添加到第一行下面。但它给了我一个错误,如元素已经是其他元素的孩子。



如何摆脱这个错误。我需要在新行中添加它下面的控件的副本(新引用)。我怎么能这样做?

任何帮助都将不胜感激....



谢谢,

Gk Prajapati

解决方案

这是WPF / Silverlight的典型问题。没有人可以给你一个完整的即用型解决方案,因为你没有提供任何代码样本。



然而,解决方案的想法很漂亮简单:你应该了解它是如何工作的,并意识到这是一个功能,而不是一个问题。你不想摆脱这个错误,你想要阻止它。实际上,这是一个非常好的功能,旨在帮助开发人员避免做一些愚蠢的事情。任何UI元素都只应添加到一个父元素。您需要找到尝试添加与某个节点的子项相同的引用的位置。



您需要了解WPF / Silverlight中的子父关系。对于Silverlight,请阅读: http://msdn.microsoft.com /en-us/library/cc189034%28v=vs.95%29.aspx [ ^ ]。



-SA

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

解决方案

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


这篇关于Silverlight用户控件中元素已经是其他元素错误的子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆