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?
EDIT: I don't think actually moving an element is the answer to my problem. I'm working with the Visual Studio SDK and was able to get a hold of the UIElement that makes up the editor pane (Extends DockPanel). I was trying to move the control from the standard editor into a custom tool window I'm developing.
This is proving to be a hack and I realized that I need multiple instances of the same control so I think a more complex solution (and less of a hack) is in store.