[英]Remove parent of an UIElement in Silverlight
I have an object of an UIElement
, how can I remove the parent of it? 我有一个
UIElement
对象,如何删除它的父对象?
I saw that there is not setter for parent property of an UIElement
. 我看到
UIElement
父属性没有设置方法。
Any suggestions will be helpful. 任何建议都会有所帮助。
EDIT : 编辑:
protected FrameworkElement Content
{
get { return this.content; }
set
{
if ((this.content != null) && (this.Children.Contains(this.content)
== true))
this.Children.Remove(this.content);
this.content = value;
if ((this.content != null) && (this.Children.Contains(this.content)
== false))
{
this.Children.Add(this.content); // here i get error Element is already an child of another
}
this.InvalidateMeasure();
this.InvalidateArrange();
}
}
UIElement.Parent
just returns the Parent as a UIElement
. UIElement.Parent
只是将Parent作为UIElement
返回。 You can cast it to the right element if you know what the parent is. 如果知道父对象是什么,则可以将其转换为正确的元素。 Lets say you have a parent this IS a
StackPanel
假设您有一个父母,这是一个
StackPanel
StackPanel parent = myelement.Parent as StackPanel;
parent.Children.Remove(myelement);//removes your element from its parent.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.