Reputation: 19937
Using Prism 5.0
. My shell is instantiated from a MefBootstrapper
derived class. The shell has a MainRegion
where views are added using the AutoPopulateExportedViewsBehavior
(found in the StockTraderRI sample). This works perfectly.
However, in one of my views that is loaded into the MainRegion
, there is a TabControl
where I want to add active-aware viewmodels in runtime. The IActiveAware
interface only works if the control is inside a region, and a region does not allow me to bind to ItemsSource
. Hence this construct:
<TabControl prism:RegionManager.RegionName="TabRegion">
<TabControl.Resources>
<DataTemplate DataType="{x:Type local:MyTabViewModel1}">
</DataTemplate>
<DataTemplate DataType="{x:Type local:MyTabViewModel2}">
</DataTemplate>
</TabControl.Resources>
</TabControl>
So I thought that I could add the viewmodels in runtime, when my main viewmodel is activated (via IActiveAware
):
protected override void OnActiveChanged(bool active)
{
if (active)
{
// This code crashes.
// The region does not exist in the root region manager...
var region = regionManager.Regions["TabRegion"];
}
}
The problem is that this code crashes. I guess this means that I have a reference to the root region manager. How do I get hold of the scoped region manager?
Upvotes: 0
Views: 393