DockControl Initialization and Defaults
DockControl wires up the factory and layout when InitializeFactory and InitializeLayout are enabled. This guide explains what the control sets up for you and when you might want to take over manually.
Factory assignment
When a Layout is assigned, DockControl checks for a factory:
- If
Layout.FactoryisnullandDockControl.Factoryis set, it assigns that factory to the layout. - If
Layout.Factoryis already set, it uses it as-is.
If neither is set, initialization stops and the control will not set up locators or call InitLayout.
InitializeFactory behavior
When InitializeFactory="True", DockControl populates the factory with default locators:
ContextLocatoris set to a new empty dictionary.DockableLocatoris set to a new empty dictionary.HostWindowLocatoris set with a default entry forIDockWindowthat creates aHostWindow.DefaultContextLocatoris set to returnDockControl.DefaultContext.DefaultHostWindowLocatoris set to return a newHostWindow.
This makes a minimal layout work out of the box, but it also means any locators you configured earlier will be replaced. If you want to populate locators yourself or integrate with dependency injection, set InitializeFactory="False" and configure the factory manually.
InitializeLayout behavior
When InitializeLayout="True", DockControl calls:
layout.Factory.InitLayout(layout);
This initializes owners, commands, and view model state for every dockable in the layout. If your factory needs additional setup (for example, custom locators), configure it before calling InitLayout.
DefaultContext usage
DockControl.DefaultContext feeds the factory fallback for ContextLocator when InitializeFactory is enabled. You can set it from code or bind it in XAML:
var dockControl = new DockControl
{
DefaultContext = new MainViewModel(),
InitializeFactory = true,
InitializeLayout = true
};
<DockControl Layout="{Binding Layout}"
Factory="{Binding Factory}"
DefaultContext="{Binding}"
InitializeFactory="True"
InitializeLayout="True" />
If you prefer to set DefaultContextLocator directly, disable InitializeFactory or assign your own locator after the control initializes.
Recommended patterns
- For quick samples and XAML-only layouts, keep both flags enabled.
- For DI-heavy apps, disable
InitializeFactoryand set locators explicitly in your factory. - Always call
InitLayoutonce after you finish building or deserializing the layout.
Related guides:
For an overview of all guides see the documentation index.