views:

303

answers:

2

We have a "legacy" WPF applicaton that is based on a NavigationWindow. The NavigationWindow has a fairly large ControlTemplate that houses a ContentPresenter as so:

<ControlTemplate>
    ....snip...
<ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
    .....snip....
    </ControlTemplate>

What we want to do is use that ContentPresenter as the first tab and dynamically add other tabs at run time. Like this:

    <ControlTemplate>
....snip...
<TabControl Background="Transparent" cal:RegionManager.RegionName="MainRegion" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
       <TabItem Header="Nav Window Content">
           <ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
       </TabItem>
    </TabControl>
.....snip....
</ControlTemplate>

Then our Modules grab the RegionName and insert their content dynamically. The issue seems to be that the PRISM region manager doesn't like that our code is in a ContentTemplate and cannot resolve the region. I have tried updating the RegionManager, adding the Region dynamically, just having a root tab control without the ContentPresenter, but I cannot get this to work. Any ideas?

A: 

Regions in templates are an issue - since templates are rendered after the initial content they arent 'controls' or even instances per-se and the region manager has no way to get handle on it. i would assume adding a region this way wouldnt be supported.

Now, staright up tab control w/ no templates I was able to get to work just fine but recall needing to write a content adapter that knew how to handle the target region type and registering that in the bootstrapper before i did the module loading.

J Rothe
Would it be possible to attach a Region to the tab after it has been rendered?
Nate Noonen
You can- but you have to get a handle to the region manager thats in use, so if you only have 1 (the global one for instance) it makes it much easier. You can create the tab then assign it as the target of a region via code after the fact- so you would load the modules then iterate over them and for each module you create a tab, assign the name, and then register that tab it as a region to the central region manager. I think you might still need a content adapter so prizm knows how how to put incoming content together.
J Rothe
I should mention prizm has been thru an overhaul since i last used it over a year ago- im not sure if the content adapter paradigm still exists but at the time that was the way you managed the views. At that time it was possible to dynamically register regions-we did it quites extensively.
J Rothe
I should also mention if what you want to register as region is still contained in a template, it wont matter when you register it -it still probably wont work (the whole template nonsense). If you are creating tabs the easiest thing to do would be to just register each tab as a region on creation. Since a tab is just a content control it should work out fine and any templates you apply to the tab after the fact should still show your content. You just cant put the region in the template.
J Rothe
A: 

So we got around this by chaning the NavigationWindow to a Frame and dropping the content in the frame. We need to do a bit of styling in order to make it look good; however, this is the only way to get around the use of a region in a NavigationWindow content template. We are now removing all code from the frame that was common to the app and will be needed by the Shell (since the NavigationWindow cannot become the Shell).

Nate Noonen