In This Article

Programmatic Layout

This topic covers several methods for programmatically arranging and resizing the docking windows.

Resizing Split Container Slots

The SplitContainer control is used to arrange the various docking elements vertically or horizontally, while also allowing dynamic resizing. The child elements of the SplitContainer are arranged into slots, which allows the elements to be sized proportionally as the SplitContainer is sized.

The SplitContainer.ResizeSlots method can be used to resize the associated slots, and therefore the underlying docking elements. The ResizeSlots method accepts zero or more ratios, represented by a double array. The ratios are used to calculate new sizes for the associated slots.

For example, this code shows a SplitContainer with two child elements, therefore the SplitContainer has two slots:

...
<docking:SplitContainer Orientation="Horizontal">
	<docking:TabbedMdiContainer>
		<docking:DocumentWindow Title="Upper-1">
			<TextBox TextWrapping="Wrap" Text="A document window in the upper-left corner of the tabbed MDI area." />
		</docking:DocumentWindow>
	</docking:TabbedMdiContainer>
	<docking:TabbedMdiContainer>
		<docking:DocumentWindow Title="Upper-2">
			<TextBox TextWrapping="Wrap" Text="A document window in the upper-right corner of the tabbed MDI area." />
		</docking:DocumentWindow>
	</docking:TabbedMdiContainer>
</docking:SplitContainer>
...

This code can be used to evenly distribute the available space between the two elements in the above example:

splitContainer.ResizeSlots();

This code can be used to give the first element twice as much space as the second element:

splitContainer.ResizeSlots(2, 1);

The only restriction on the ratios passed is that they are greater than 0. If there are more ratios than there are slots, then the extra ratios will be ignored. If there are more slots than there are ratios, then the last ratio will be repeated for the remaining slots. As a result, passing a single ratio is equivalent to not passing any ratios, since all the slots will share the same ratio.

There is no way to indicate that one slot should use star (*) sizing. Instead, take into account the current size of the split container and adjust the ratios passed to the ResizeSlots method to get child controls into their desired sizes.

The above code shows how to call the ResizeSlots method, but does not illustrate how the reference to the SplitContainer was obtained.

Warning

You should never use XAML x:Name references to obtain a specific SplitContainer, as these elements are created and destroyed dynamically as changes are made to the docking layout.

The VisualTreeHelper and VisualTreeHelperExtended can be used to locate the various SplitContainer elements currently used. VisualTreeHelperExtended offers several helper methods for walking up and down the visual tree.

See the Media topic for more information on VisualTreeHelperExtended.

Reversing Split Container Slots

A SplitContainer.ReverseSlots helper method is available that reverses the order of all the children in the container.

This code reverses the order of the SplitContainer's children:

splitContainer.ReverseSlots();

Arranging Tabbed MDI Windows

See the Tabbed MDI topic for more information on arranging tabbed MDI windows.

Arranging Standard MDI Windows

See the Standard MDI topic for more information on arranging standard MDI windows.

Setting Docking Window Initial Sizes

See the Lifecycle and Docking Management topic for more information on setting a different default initial size for docking windows.

Setting Docking Window Default Locations

See the Lifecycle and Docking Management topic for more information on setting a different default location for docking windows.