This question is related to following thread.
Prism RegionAdapter – Removing then Adding View
My post to this thread was deleted my admin, saying it was answered and I need to start new thread. Please let me know if any of you have solved this issue.
My deleted post was…
How did you manage to get rid of “Specified element is already the logical child of another element. Disconnect it first.” error with closing event. I tried the same thing, on closing I remove the dockablecontent from the documentpane. But it doesn’t help I keep getting this error. Once I remove the view, and then later try to add it again the same way you are adding, I get this error.
Please help me, I am not sure what am I missing. I have wasted so much of time trying to get around it but no luck yet.
Here is the code I am using:
<ad:DockableContent ...
x:Name="viewRoot"
IsCloseable="True" HideOnClose="False"
Title="{Binding Title}">
<ContentControl Grid.Row="1" Content="{Binding View}"/>
</Grid>
</ad:DockableContent>
It gets used inside this:
<ad:DockingManager x:Name="DockingManagerControl" Grid.Column="1">
<ad:ResizingPanel x:Name="MainResizingPanel" ResizeWidth="*" ResizeHeight="*" Orientation="Horizontal">
<ad:DockablePane ad:ResizingPanel.ResizeWidth="0.25*" prism:RegionManager.RegionName="ProjectBrowserRegion"/>
<ad:ResizingPanel x:Name="PespectiveResizingPanel" ResizeWidth="0.75*" ResizeHeight="*" Orientation="Horizontal">
<ad:DocumentPane x:Name="DockablePaneControl"/>
</ad:ResizingPanel>
</ad:ResizingPanel>
</ad:DockingManager>
View content bindings are UI element which comes from separate dlls, So I don’t have them as View/ViewModel pair. So I can’t use ContentTemplate+DataContext way here. Things load nicely, but use can select/deselect these views. So if a view has been opens the view selection dialog again, then I clear all views (I remove it from DockablePaneControl Items.Clear()), and add the selected views again (DockablePaneControl Items.Add()), then I get this error.
Usually this occurs because you are trying to assign the same control to two different parents.
I often see this issue with Styles, where a non-template property that contains Controls is set in a Style, such as
ContentControl.Content, orDataGridColumn.HeaderFor example, if your style sets
ContentControl.Content, and you add two ContentControls to your Window, you’ll encounter this error because the style is trying to assign the same controls inside theContentsection of both ContentControls. The fix is to set a template style, such asContentControl.ContentTemplateinstead ofContentControl.Content. I like to say this is like giving multiple people the same cookie to it – it just doesn’t work. You have to give them each the cookie cutter (template) instead so they can make their own.I actually see questions about this error so much that I wrote a blog post about it