Hi,
I'm trying to re-create content panes from code as part of different default views requirement. But I'm encountering an error whenever I unpin a content pane and trying to add the same to a split pane in another view.
Error:
Specified element is already the logical child of another element. Disconnect it first.
I tried to disconnect it in various ways unsuccessfully.
contentPane.ExecuteCommand(ContentPaneCommands.TogglePinnedState);
when I use the below code. I get a different error: Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
((UnpinnedTabArea)contentPane.Parent).Items.Clear();
Could you please help me resolving the issue asap.
Thanks,
This sounds like what I described here. Try setting the CloseAction of the ContentPane to RemovePane (if it's not already set), execute the ContentPaneCommands.Close command and then reset the CloseAction (if you had to change it). In this way all the internal references to the ContentPane should be removed.