This project is read-only.

Exception Nested DockingManager's Using Prism....

Oct 23, 2013 at 8:03 PM
Edited Oct 23, 2013 at 8:05 PM
Hi,

Thanks again for a awesome Control! I'm trying to create a Multi Level DockingManager interface, but I keep getting this Exception when I try to reload and inject more than one View back into the Sub Main View of the DockingManager using Prism explained below.

Using: Prism's MEF

MainView (RibbonWindow):
    <RibbonWindow.Resources>
        <DataTemplate DataType="{x:Type NatarVM:TurahStudyUIViewModel}">
            <NatarV:TurahStudyUIView x:Name="Natsar"/>
        </DataTemplate>
    </RibbonWindow.Resources>
TurahStudyUIView (UserControl): The Main DockingManager interface
<xcad:DockingManager 
    x:Name="TurahDockingManager" 
    Grid.Row="1" 
    prism:RegionManager.RegionName="{x:Static inf:RegionNames.MainRegion}" 
    TabIndex="{Binding Path=PropertiesService.DockingManagerTabIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    ActiveContent="{Binding Path=PropertiesService.DockingManagerActiveContent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    Theme="{Binding AvalonDockTheme}">
    <xcad:DockingManager.LayoutItemContainerStyle>
        <Style TargetType="{x:Type xcad:LayoutItem}" BasedOn="{StaticResource DocumentItem}"/>
    </xcad:DockingManager.LayoutItemContainerStyle>
    <xcad:LayoutRoot >
        <xcad:LayoutPanel Orientation="Horizontal">
            <xcad:LayoutDocumentPane/>
        </xcad:LayoutPanel>
    </xcad:LayoutRoot>
</xcad:DockingManager>
Here using Prism to inject multiple Sub Main Views with a DockingManager with the same layout as above each with a unique name.

CreateWritingsView (UserControl): The Sub Main DockingManager interface
<xcad:DockingManager 
    x:Name="CreateDockingManager" 
    prism:RegionManager.RegionName="{x:Static inf:RegionNames.CreateWritingsRegion}" 
    TabIndex="{Binding Path=PropertiesService.DockingManagerCreateTabIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    ActiveContent="{Binding Path=PropertiesService.DockingManagerCreateWritingsActiveContent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    Theme="{Binding AvalonDockTheme}">
    <xcad:DockingManager.LayoutItemContainerStyle>
        <Style TargetType="{x:Type xcad:LayoutItem}" BasedOn="{StaticResource DocumentItem}"/>
    </xcad:DockingManager.LayoutItemContainerStyle>
    <xcad:LayoutRoot >
        <xcad:LayoutPanel Orientation="Horizontal">
            <xcad:LayoutDocumentPane/>
        </xcad:LayoutPanel>
    </xcad:LayoutRoot>
</xcad:DockingManager>
and within each of these Sub Main View I need to use a DockingManager to organize each User Interface View. I hope I'm not confusing you.

For example, CreateEnglishWritingsView (UserControl) is one of the user interfaces injected into the DockingManager of CreateWritingsView (UserControl).

As the user opens these Views I save open information to a config file and reopen them during startup. Each interface is injected from an Assembly Module using Prism MEF. Everything works fine during program uptime, its when I try to inject more than one View into CreateWritingsView (UserControl) DockingManager during startup I get this Exception:
An unhandled exception of type 'System.NullReferenceException' occurred in Xceed.Wpf.AvalonDock.dll

Additional information: Object reference not set to an instance of an object.

If there is a handler for this exception, the program may be safely continued.
And when I remove one of the two Views to be reloaded everything works fine. So it looks like I'm going to have to re-think on how to do this layout interface if there is no solution or there is a limit.

I get this long "Call stack with external code" list and I can't copy it to post it here, but it begins with "Xceed.Wpf.AvalonDock.dll!Xceed.Wpf.AvalonDock.DockingManager.DockingManager_Unloaded(object sender, System.Windows.RoutedEvetArgs e).........
Jan 18, 2014 at 12:23 PM
I am trying to do something similar, I think. I have a docking manager in the main window and that docking manager contains anchorables that also contain docking managers of their own. I am not sure that your problem is the same that I had, but here is how I managed to get mine to be able to serialise and de-serialise:

I force the views to actually display all anchorables before serialising. Also, after de-serialising the docking manager of the main window, I do this again before de-serializing the anchorables within.

I think that this is a rather ugly solution, but it appears to work. What I do is iterate through all the anchorables in the docking manager of the main window, make them active and force them to update their layout:
        protected void forceViews()
        {
            // Force intantiation of views for the AvalonDockingManager so that
            // loading of the layout from MainWindowViewModel will work at start-up:
            foreach (object o in _workspacesDockingManager.AnchorablesSource)
            {
                _workspacesDockingManager.ActiveContent = o;
                _workspacesDockingManager.UpdateLayout();
            }
            // Activate the first anchorable:
            IEnumerator i = _workspacesDockingManager.AnchorablesSource.GetEnumerator();
            i.MoveNext();
            _workspacesDockingManager.ActiveContent = i.Current;
        }
The ugly part here is that this code lives in my view model and _workspacesDockingManager is a reference to a part of the view.

If anyone has a better solution, I'd be happy to hear it.