From discussion
https://avalondock.codeplex.com/discussions/445523
Closing a LayoutAnchorable doesn't seems to remove its content from the visual tree.
-=-=-=-=-=-=
I have an application with __two docking managers__.
First I am adding Control1 is added to the dockingManager1 . At a later time I want to __move Control1 from dockingManager1 to dockingManager2__ . I can't figure out how. I get the exception
> Specified element is already the logical child of another element. Disconnect it first
My Code for adding initially is -
```
layoutAnchorable = new LayoutAnchorable() { ContentId = "Help", Title = "Help", Content = Control1, };
layoutAnchorable.AddToLayout(dockingManager1, AnchorableShowStrategy.Top);
```
-------------------------------------------------------------------------------
To move later I tried -
```
layoutAnchorable.Close();
layoutAnchorable.Content = null;
LayoutAnchorable newLayoutAnchorable = new LayoutAnchorable() { ContentId="Help", Title = "Help", Content = Control1 };
newLayoutAnchorable.AddToLayout(dockingManager2, AnchorableShowStrategy.Top);
```
Whatever I do - it gives the same exception. __Note:__ I want to use the same control - not create a new instance. What do I have to do - to have the control removed from dockingManager1 's dependency tree completely.
thanks,
V
Comments: ** Comment from web user: emartin **
I was on the steps of resolvig the problem.
There is a commented line in DockingManager in this method:
DockingManager.CollectLayoutItemsDeleted()
The commented line remove the anchorable content from the dockingmanager logical children. I absolutely don't know why Adospace commented this line. It was initaly checked in as is.
But it is only part of the story.
1. You also need to get rid of the "LayoutElement._root" field, which is some kind of a cache to the "Root" dynamic property. Just call "Root" instead of refering the "_root" field.
2.
DockingManager.CollectLayoutItemsDeleted() "Dispatch" the execution of the cleanup. Removing the "dispatching" operation and simply do the cleanup at once resolve your problem, but re-add an old one. The reason why Adospace checked in this "dispatch" is to fix the issue explained in [this discussion](http://avalondock.codeplex.com/discussions/399931). So to avoid to re-insert an old problem to fix a new one, I was studying a way to fix this old issue without "dispatching" the execution in this method. Not complete yet.