The following example shows how to create layout items (DevExpress.Xpf.Docking.LayoutPanel and DevExpress.Xpf.Docking.DocumentPanel objects) from a data source according to the MVVM design pattern and how to implement template selection.
In this example, the MainViewModel class provides the Items collection that contains objects to be rendered as layout items in the DevExpress.Xpf.Docking.DockLayoutManager. An instance of the MainViewModel class is assigned to the Window's DataContext. The DevExpress.Xpf.Docking.DockLayoutManager.ItemsSource property is bound to the Items property in the MainViewModel. This way, the DevExpress.Xpf.Docking.DockLayoutManager gets the source of objects to be visualized as layout items.
The Items collection contains items of two types:
1)ViewModel objects - contain data for creating DevExpress.Xpf.Docking.LayoutPanels
2)DocumentViewModel objects - contain data for creating DevExpress.Xpf.Docking.DocumentPanels
There are two templates declared in XAML that render input objects as either DevExpress.Xpf.Docking.LayoutPanels or DevExpress.Xpf.Docking.DocumentPanels.
The custom DockItemTemplateSelector class overrides the SelectTemplate method to choose a template that corresponds to a specific item in the DevExpress.Xpf.Docking.DockLayoutManager.ItemsSource. This template selector is assigned in XAML to the DevExpress.Xpf.Docking.DockLayoutManager.ItemTemplateSelector property.
In this example, the DevExpress.Xpf.Docking.DockLayoutManager contains two groups explicitly created in XAML: a DevExpress.Xpf.Docking.LayoutGroup named panelHost and a DevExpress.Xpf.Docking.DocumentGroup named documentHost. Items from the Items collection are automatically placed in one of these groups based on their IMVVMDockingProperties.TargetName property values.