Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
740
LoadLayout() failure: Specified element is already the logical child of another element.
posted

I have a XamDockManager control with MDI-style ContentPanes.  My tabs are bound.  I am using Attached Properties to manage the tabs.  I am using using Dependency Properties to handle loading and saving the layout. 

On start up everything works as expected.  My problem starts when I tear off one of my previously tabbed panes.  SaveLayout() work correctly.  If I shut down the app and restart it the load fails during xamDockManager.LoadLayout(path_to_saved_layout).  

"Specified element is already the logical child of another element. Disconnect it first."  

If I leave all of my bound, MDI-style panes as-is on start-up, there are no problems reloading the layout original layout.  Tearing off non-bound panes, doesn't cause any problems either.  

This seems to me to be a sequencing problem.  The tab already exists before the XamDockManager.Loaded Event which is what kicks off LoadLayout().  But I don't know what the final layout will be until I've applied the saved layout, so I don't know which content panes go where.  More specifically, I don't know which content panes should be orphaned before I load the layout.  I suppose I could crack open the XML file and manually parse the layout generated by LoadLayout() but that seems counter-productive.  

Any suggestions on how to get around this problem while still allowing my users the ability to save their custom layouts?