Max Young
Max Young

Reputation: 1662

How do I programatically add more panes to a avalon dock

I am working with avalon dock v2 and all I am trying to do is have it so when I hit a button it adds another pane to my layout.

This is my existing pane but I don't know the syntax to add another pane to it when I press a button.

<avalonDock:DockingManager x:Name="dockingManager">
    <avalonDock:LayoutRoot>
        <avalonDock:LayoutPanel Orientation="Horizontal">
            <avalonDock:LayoutDocumentPaneGroup >
                <avalonDock:LayoutDocumentPane x:Name="mainDocumentPaneGroup">
                               
                </avalonDock:LayoutDocumentPane>
            </avalonDock:LayoutDocumentPaneGroup>
        </avalonDock:LayoutPanel>
    </avalonDock:LayoutRoot>
 </avalonDock:DockingManager>

Here is what I put inside the button.

 DockPanel CNPCTab = new DockPanel() { };
 CNPCTab.Name = "CNPCTab";

 mainDocumentPaneGroup.

I don't really see any methods that would allow me to add the pane I initialized to group I initialized in the xaml.

Upvotes: 1

Views: 3035

Answers (1)

John Fairbanks
John Fairbanks

Reputation: 1422

I don't know if you still need an answer to this or not, but I needed it as well and couldn't really find a good answer anywhere so I'm provding it here. You need to create a LayoutArchorable, set its Content to your UserControl, and then call the AddToLayout method on the LayoutArchorable to get it to add itself. In my case I wanted the new window to start as Floating so the user could decide where to drop it, but you still have to assign it somewhere before it can float.

    LayoutAnchorable la = new LayoutAnchorable { Title = "New Window", FloatingHeight = 400, FloatingWidth = 500, Content = new YourUserControl() };
    la.AddToLayout(dockingManager, AnchorableShowStrategy.Right);
    la.Float();

In this example, I named the DockingManager in the XAML so I could access it from the code behind.

Upvotes: 10

Related Questions