Search code examples
silverlightprismregions

Prism regions not displaying registered views


I'm using PRISM in a SilverLight 4 application. I have a problem where views registered to some regions doesn't get displayed.

When loading a module at startup I register some views to regions as follows:

RegionManager.RegisterViewWithRegion("MyRegion1", typeof(IMySubView1));
RegionManager.RegisterViewWithRegion("MyRegion2", typeof(IMySubView2));

I have a view implementing an interface called IMyView, where the xaml have two contentcontrols with regions defined in a grid like this:

<ContentControl Regions:RegionManager.RegionName="MyRegion1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Row="0" Grid.RowSpan="1"/>
<ContentControl Regions:RegionManager.RegionName="MyRegion2" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Row="1" Grid.RowSpan="1"/>

I have tried two different methods for adding the view to the main region. Both adds the view and basic elements such as buttons get displayed, but the regions defined in the view does not get filled with associated views.

Method 1:

object obj = _container.Resolve<IMyView>();
IRegion mainRegion = _regionManager.Regions["MainViewRegion"];
IRegionManager scoped = mainRegion.Add(obj, "test", true);
mainRegion.Activate(obj);

// Enabling the following call, it will fail saying the region MyRegion1 does not exist. Feels like it should?
// IRegion myRegion = scoped.Regions["MyRegion1"];

Method 2:

object obj = _container.Resolve<IMyView>();
_regionManager.AddToRegion("MainViewRegion", obj);
_regionManager.Regions["MainViewRegion"].Activate(obj);

It feels like the regions defined in the xaml file doesn't get registered, and because of that the registered views do not get displayed.

The MainViewRegion is defined in the shell in a TabControl as this:

<TabControl Margin="8,0,8,8" Regions:RegionManager.RegionName="MainViewRegion">

Any suggestions on solving my problem will be greatly appreciated!


Solution

  • The problem is gone in Prism version 4.0, I was running Prism version 2.2 when the problem occured.