Back to Devexpress

DockLayoutManager.ItemsSource Property

wpf-devexpress-dot-xpf-dot-docking-dot-docklayoutmanager-e20de2eb.md

latest6.9 KB
Original Source

DockLayoutManager.ItemsSource Property

Gets or sets a collection of objects providing information to generate and initialize layout items for the DockLayoutManager. This is a dependency property.

Namespace : DevExpress.Xpf.Docking

Assembly : DevExpress.Xpf.Docking.v25.2.dll

NuGet Package : DevExpress.Wpf.Docking

Declaration

csharp
public IEnumerable ItemsSource { get; set; }
vb
Public Property ItemsSource As IEnumerable

Property Value

TypeDescription
IEnumerable

The source of objects to be visualized as layout items.

|

Remarks

The ItemsSource property supports the MVVM design pattern.

To populate the DockLayoutManager with existing panels, the ViewModel should implement the IMVVMDockingProperties interface. The TargetName property should return the name of the target layout group where DockLayoutManager places the created dock panel.

The following code sample populates DockLayoutManager with the ChildViews ViewModel collection:

csharp
public class MainViewModel : ViewModelBase {
        public ObservableCollection<PanelViewModel> Panels {
            get { return GetValue<ObservableCollection<PanelViewModel>>(); }
            set { SetValue(value); }
        }

        public MainViewModel() {
            Panels = new ObservableCollection<PanelViewModel>() {
                new PanelViewModel() { Caption = "One", Content = "A regular panel", TargetName = "documentGroup" },
                new PanelViewModel() { Caption = "Two", Content = "A regular panel", TargetName = "documentGroup" },
                new PanelViewModel() { Caption = "Three", Content = "A regular panel", TargetName = "documentGroup" },                
                new PanelViewModel() { Caption = "Five", Content = "A panel", TargetName = "layoutGroup" },
            };
        }
    }    

    public class PanelViewModel : ViewModelBase, IMVVMDockingProperties {
        public string Caption {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public string Content {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }        
        public string TargetName {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
    }
xaml
<UserControl ...
    xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking">
    <UserControl.DataContext>
        <ViewModels:MainViewModel />
    </UserControl.DataContext>
    <Grid>
        <dxdo:DockLayoutManager ItemsSource="{Binding Panels}">
            <dxdo:DockLayoutManager.Resources>
                <Style x:Key="BaseStyle"
                       TargetType="dxdo:LayoutPanel">
                    <Setter Property="Caption" Value="{Binding Caption}" />
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding Content}" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style BasedOn="{StaticResource BaseStyle}" TargetType="dxdo:LayoutPanel" />
                <Style BasedOn="{StaticResource BaseStyle}" TargetType="dxdo:DocumentPanel" />
            </dxdo:DockLayoutManager.Resources>
            <dxdo:LayoutGroup x:Name="root">
                <dxdo:LayoutGroup Name="layoutGroup" />
                <dxdo:DocumentGroup Name="documentGroup" />
            </dxdo:LayoutGroup>
        </dxdo:DockLayoutManager>
    </Grid>
</UserControl>

You can use the DockLayoutManager.ItemTemplate or DockLayoutManager.ItemTemplateSelector properties to customize the appearance of layout items that are stored in the ItemsSource collection.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ItemsSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-docklayoutmanager-use-imvvmdockingproperties-to-build-dock-ui-with-mvvm/CS/MainWindow.xaml#L10

xml
</Grid.Resources>
<dxdo:DockLayoutManager Name="dockLayoutManager1" DataContext="{StaticResource viewModel}" ItemsSource="{Binding ChildViews}">
    <dxdo:DockLayoutManager.LayoutRoot>

wpf-docklayoutmanager-use-layoutadapter-to-build-dock-ui-with-mvvm/CS/dxSampleGrid/MainWindow.xaml#L23

xml
</Grid.Resources>
<dxdo:DockLayoutManager ItemsSource="{Binding PersonList}">
    <dxdo:MVVMHelper.LayoutAdapter>

wpf-dock-layout-manager-pin-unpin-layout-panels-in-mvvm/CS/MainWindow.xaml#L18

xml
<Button Content="UnPin Messages" Command="{Binding UnpinMessagesCommand}" Grid.Row="1"/>
<dxdo:DockLayoutManager Grid.Row="2" Name="dockLayoutManager1" ItemsSource="{Binding ChildViews}">
    <dxdo:DockLayoutManager.LayoutRoot>

See Also

ItemTemplate

ItemTemplateSelector

MVVM Support - Bind to a Collection of Dock Panels

DockLayoutManager Class

DockLayoutManager Members

DevExpress.Xpf.Docking Namespace