Adding a Prism region to ToolWindowContainer

Docking/MDI for WPF Forum

Posted 11 years ago by Jesse Lai - Sandia National Labs
Version: 12.2.0571
Avatar

Hello,

I'm trying to use Prism to make the UI in my application composable and more maintainable.  In my Shell.xaml (top level view), I define the DockSite and add some ToolWindowContainers that define the various regions.  One of those is a region where I want to add additional dockable items defined in other modules.  I do that like this:

<!--  Model  -->
<docking:ToolWindowContainer docking:DockSite.ControlSize="400,400">
  <docking:ToolWindow x:Name="deviceToolWindow"
                      Title="Device"
                      prism:RegionManager.RegionName="{x:Static m:RegionNames.DeviceRegion}" />
</docking:ToolWindowContainer> 

In the region, I would like to include additional tool windows that are dockable in the main docksite.  So, for example, the DeviceView.xaml is hooked up in Prism so it is the view that is loaded into the DeviceRegion.  It is a UserControl with the following in it (minus all other namespace declarations, etc):

<docking:ToolWindowContainer docking:DockSite.ControlSize="400,400">
        <docking:ToolWindow x:Name="outputGroupWindow"
                            Title="Output"
                            prism:RegionManager.RegionName="{x:Static m:RegionNames.OutputsGroupRegion}" />
</docking:ToolWindowContainer>

What I actually want in the DeviceView is to be able to just define a ToolWindow, but that does not work correctly. I wasn't able to define a ToolWindowContainer as a Prism region.  So I had to define a new ToolWindowContainer.  I'd like to be able to just define a ToolWindow in the DeviceView.xaml code and it would use the ToolWindowContainer in the parent Shell class.  I wasn't able to get that to work.  If I define just the ToolWindow, nothing actually gets loaded into the region.  Is there a way to make that work?

To work around that issue, I created teh ToolWindowContainer in the DeviceView.xaml.  However, when the application is run, if the DeviceRegion is dragged around into any of the other dockable areas, an exception occurs.  I assume this is because the toolwindow is not correctly registered with the DockSite properly.  I get an InvalidOperationException "Attempt to remove from unknown parent class...".

So I essentially have two questions:

1) What is the proper way of defining a ToolWindow in a custom UserControl so it will correctly locate the ToolWindowContainer up in the hierarchy?

2) What is the proper way of defining a ToolWindowContainer in a custom UserControl so it will bind to the DockSite appropriately to allow docking?

Comments (1)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jesse,

Sorry but you can't really do either of those things.  We need to be the ones making ToolWindowContainers, the only exception being if you have a default layout in XAML.  And you can't define a ToolWindow in a UserControl.

Instead what you should be defining your ToolWindow content in a UserControl.  And let us handle wiring up a ToolWindow with it.  We have a nice Prism sample project that comes with WPF Studio and shows the concept in detail.  Please check that out as it should help you get the concepts correct.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.