Programatically add to Panel TabGroup

Jun 3, 2008 at 11:46 PM
In my application I am programmatically creating some controls that I would like to dock around my main document.  I got the first control to work by wrapping the control in a DockableContent, wrapping that in a DockablePane, and calling dockingManager.Anchor(pane,document,anchorStyle).  When I go to add the 2nd control I would like it to be added as a tab on the existing pane if there is already a Pane docked in the requested anchor position.  Instead what it is doing is adding another pane next to the existing one.

How would I go about adding the 2nd control as a tab, instead of as a new pane?  It seems like I should be able to query something (the dockingManager, or the document we are docked around?) to figure out if a pane is already docked, and if so add myself to that panes content instead of creating a new pane.  However, I haven't been able to figure out where to check for the already docked pane.  Anyone have any ideas?

Thanks!
Jun 4, 2008 at 9:04 AM
Hi,
if you want to add a DockableContent into an existings DockablePane, you need a reference to the pane and use code like this:
myPane.Items.Add(myContent);

To get a reference to an existings DockablePane follow code like this:

DockablePane existingsPane = myFirstAddedContent.Parent as DockablePane.
if (existingsPane != null) //check always
    existingsPane.Items.Add(secondContent)

(if you don't have a reference to a previously added content, find it in the array of contents you can get back from DockManager.Contents)

Jun 4, 2008 at 5:08 PM
Hi, Thanks for the response, thats looks pretty straightforward.  Is there any way to check where a pane is docked?
Jun 5, 2008 at 10:34 AM
Use DockablePane.IsDocked and DockableContent.State to get single content state.
Jun 5, 2008 at 6:32 PM
Cool, got it to work.  Just an fyi for anyone reading this in the future, the dockingmanager doesn't have a "Contents" of DockablePanes, it just has one Content which is something else, but you can get a an array of DockableContents, and from them get the parent panes.
Jun 5, 2008 at 11:48 PM
Cool, got it to work.  Just an fyi for anyone reading this in the future, the dockingmanager doesn't have a "Contents" of DockablePanes, it just has one Content which is something else, but you can get a an array of DockableContents, and from them get the parent panes.
Jun 6, 2008 at 9:06 AM
Yes, DockingManager has 5 useful properties:
- DockableContents returns an array of all the DockableContent contained (that are usually a fixed number defined by user of the library)
- Documents returns an array of all the DocumentContent
- ActiveContent is the currently active content with keyboard focus (this can be a DockableContent or DocumentContent so returns an object of type ManagedContent)
- ActiveDockableContent is the currently active DockableContent (could be the same as ActiveContent)
- ActiveDocument is the currently active DocumentContent (could be the same as ActiveContent)

I'm planning to add DockablePanes/ActivePane properties to get an array of all the panes created and the currently focused one respectively.
Anyway any object of type ManagedContent/Pane can be retrieved traversing the logicaltree with root DockingManager.
Jun 19, 2008 at 1:18 AM
Edited Jun 19, 2008 at 1:30 AM

I was able to create an extension method that will add docable content panes without needing a reference to an existing pane. I like to use extension methods when I can because it allows me to download new versions of the docking components without losing my changes/additions.

 

public static void LoadNewDockableContent(this DockingManager DocManager, UserControl Content, string Name, string Title, string IconSource, Brush Background, AnchorStyle AnchorTo, bool AutoHide)

DockablePane PaneToAnchor = new DockablePane(); 

PaneToAnchor.SetValue(
ResizingPanel.ResizeWidthProperty, 200.0); 
PaneToAnchor.SetValue(
ResizingPanel.ResizeHeightProperty, 200.0); 

DockableContent
dc = new DockableContent(); 
dc.Name = Name;
dc.Content = Content;
dc.DockableStyle =
DockableStyle.Document;
dc.Title = Title;
dc.IconSource = IconSource;
dc.Background = Background;
dc.IsEnabled =
true;

PaneToAnchor.Items.Add(dc);

DocManager.Anchor(PaneToAnchor, AnchorTo);
}

 

Hope this helps,
Tom