Programatically dock content...

Dec 3, 2008 at 2:50 PM
I just start using AvalonDock and it looks awesome! I was trying to give the user a few automatic options, tile and tab. I started with just a set number of DockableContents (4), and was able to programatically tile them or place them in tabs in a DocumentPane, using some ResiszingPanels. The first problem I ran into was trying to redock a DockableContent after the user has drug it off into a floating window. When I try assign that content to a DocumentPane or DockablePane I get an error saying the "Element already has a logical parent". I understand what the error is saying (DockableContent now belongs to the floating window), but not sure how to get around it correctly. Also, I'm sure there is a better way to automatically tile or tab all dockablecontents; but just have not found it yet. Any help is greatly appreciated!

XAML:

 

 

<DockPanel LastChildFill="True">

 

 

 

<ToolBar DockPanel.Dock="Top">

 

 

 

<Button Height="30" Name="TabViewBtn" Content="Tab View" Click="TabViewBtn_Click"/>

 

 

 

<Button Height="30" Name="TileViewBtn" Content="Tile View" Click="TileViewBtn_Click"/>

 

 

 

</ToolBar>

 

 

 

<ad:DockingManager Background="White" x:Name="dockManager">

 

 

 

<ad:ResizingPanel x:Name="resizeMain" Orientation="Vertical">

 

 

 

<ad:ResizingPanel x:Name="resizeTop" Orientation="Horizontal" >

 

 

 

<ad:DockablePane x:Name="dockPane1">

 

 

 

<ad:DockableContent x:Name="cnt1" Title="Canvas1">

 

 

 

<Canvas x:Name="canv1" />

 

 

 

</ad:DockableContent>

 

 

 

</ad:DockablePane>

 

 

 

<ad:DockablePane x:Name="dockPane2">

 

 

 

<ad:DockableContent x:Name="cnt2" Title="Canvas2">

 

 

 

<Canvas x:Name="canv2" />

 

 

 

</ad:DockableContent>

 

 

 

</ad:DockablePane>

 

 

 

</ad:ResizingPanel>

 

 

 

<ad:ResizingPanel x:Name="resizeBottom" Orientation="Horizontal">

 

 

 

<ad:DockablePane x:Name="dockPane3">

 

 

 

<ad:DockableContent x:Name="cnt3" Title="Canvas3">

 

 

 

<Canvas x:Name="canv3" />

 

 

 

</ad:DockableContent>

 

 

 

</ad:DockablePane>

 

 

 

<ad:DockablePane x:Name="dockPane4">

 

 

 

<ad:DockableContent x:Name="cnt4" Title="Canvas4">

 

 

 

<Canvas x:Name="canv4" />

 

 

 

</ad:DockableContent>

 

 

 

</ad:DockablePane>

 

 

 

</ad:ResizingPanel>

 

 

 

</ad:ResizingPanel>

 

 

 

</ad:DockingManager>

 

 

 

</DockPanel>

 


Here is the code for placing the contents into tabs
//docPane is a DocumentPane

 

private void Clear()

 

{

docPane.Items.Clear();

resizeMain.Children.Clear();

resizeTop.Children.Clear();

resizeBottom.Children.Clear();

dockPane1.Items.Clear();

dockPane2.Items.Clear();

dockPane3.Items.Clear();

dockPane4.Items.Clear();

}

 

private void TabViewBtn_Click(object sender, RoutedEventArgs e)

 

{

Clear();

resizeMain.Children.Add(docPane);

docPane.Items.Add(cnt1);

docPane.Items.Add(cnt2);

docPane.Items.Add(cnt3);

docPane.Items.Add(cnt4);

}