I have an object of an UIElement
, how can I remove the parent of it?
I saw that there is not setter for parent property of an 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
. 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 parent = myelement.Parent as StackPanel;
parent.Children.Remove(myelement);//removes your element from its parent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.