简体   繁体   中英

Add PRISM Region Manager In Existing Navigation Window

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?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM