WPF FrameworkElement Parent and Moving a UIElement

Posted by Adam Driscoll on Stack Overflow See other posts from Stack Overflow or by Adam Driscoll
Published on 2010-04-06T04:16:51Z Indexed on 2010/04/06 4:23 UTC
Read the original article Hit count: 888

Filed under:
|
|
|

I'm trying to move a control from one parent to another (if this will work I'm not quite sure). I can get a hold of the control that I want to move. Here is my code:

public void MoveElement(UIElement uiElement)
{
    var element = ((FrameworkElement)uiElement).Parent;
    //TODO:Remove from parent
    myControl.Children.Add(uiElement);
}

When I hit the last statment an ArgumentException is thrown stating "Specified Visual is already a child of another Visual or the root of a CompositionTarget." The strange thing is that Parent is returning null. How do locate the parent? Will this even work?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about uielement