Nested docksites with MVVM

Docking/MDI for WPF Forum

Posted 2 months ago by Molly
Version: 22.1.1
Avatar

I have a MainView with a Docksite that contains a TabbedMDIHost and ToolWindow. This is bound using DocumentItemsSource to a ObservableCollection of Views in my MainViewModel, lets call them ObservableCollection<Child1View> Child1ViewCollection.

In MAINVIEW.XAML

<docking:DockSite x:Name="dockSite" DocumentItemsSource="{Binding Child1ViewCollection}">

       <docking:SplitContainer Orientation="Horizontal">

                <docking:ToolWindowContainer >
                    <docking:ToolWindow Title="Open Workspaces" DefaultDockSide="Left" Style="{StaticResource ToolWindowStyle}">
                        <...ToolWindowContents>

                    </docking:ToolWindow>
                </docking:ToolWindowContainer>

                <docking:Workspace>
                    <docking:TabbedMdiHost x:Name="TabbedMdiHost_Workspaces" TabStripPlacement="Top"/>
                </docking:Workspace>
            </docking:SplitContainer>
        </docking:DockSite>

Each Child1View.xaml then contains their own Docksite, bound in their DocumentItemsSource to an ObservableCollection<Child2View> Child2ViewCollection in Child1ViewModel.

In CHILDVIEW1.XAML

<docking:DockSite x:Name="dockSite_Child" DocumentItemsSource="{Binding Child2ViewCollection}">
                <docking:Workspace>
                <docking:TabbedMdiHost>
                        <docking:TabbedMdiContainer x:Name="TabbedMdiHost" TabStripPlacement="Top">
                        </docking:TabbedMdiContainer>
                </docking:TabbedMdiHost>
                </docking:Workspace>
            </docking:DockSite>

In my MainView the tab control populated with Child1View tabs works perfectly and fires WindowsRegistered / SourceChanged events when the collection is changed. But within the child view, although the Child2ViewCollection is initialised and populated, the views are never opened, no Window Registered / Requested or SourceChanged Events fire. If I explicitly add a document window in using XAML it does appear.

Any advice on where I am going wrong when the implementation of both docksites is the same?

[Modified 2 months ago]

Comments (1)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Molly,

Hmm, I would expect that to work in general.  One note is that you don't need to put a TabbedMdiContainer in the ChildView1.xaml because containers are generated as needed.  And really you should never put a x:Name or reference specific TabbedMdiContainers since they are created/destroyed as layouts change.  You DO want to keep Workspace and TabbedMdiHost elements in the XAML though, as those are fixed.  That wouldn't affect your scenario here though.

Maybe you could add something to the ChildView1.xaml that prints out what the DataContext is ("{Binding}") in a TextBlock and also another TextBlock to show what "{Binding Child2ViewCollection.Count}" is?  Perhaps the DataContext isn't what you think it is and that's why nothing is showing?

If it does come through as being populated correctly but still no document windows are generated, please make a new simple sample project showing this happening and email it to our support address.  Reference this thread in your email and exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Then we can debug with that and see what's happening.  Thanks!


Actipro Software Support

The latest build of this product (v22.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.