Regions not displaying registered views

Topics: Prism v2 - Silverlight 4
Aug 9, 2010 at 1:04 PM

I'm using PRISM v2 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);

// 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);

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!


Aug 11, 2010 at 4:18 PM

After many hours of troubleshooting I found something.

In Composite.Presentation\Regions\RegionManager.cs there is a method called IsInDesignMode. When a region is about to be created this method is called, and if this method returns true the region is not created. See below:


        private static void OnSetRegionNameCallback(DependencyObject element, DependencyPropertyChangedEventArgs args)
            if (!IsInDesignMode(element))

        private static bool IsInDesignMode(DependencyObject element)
            // Due to a known issue in Cider, GetIsInDesignMode attached property value is not enough to know if it's in design mode.
            return DesignerProperties.GetIsInDesignMode(element) || Application.Current == null
                   || Application.Current.GetType() == typeof(Application);


When our silverlight application starts up and the regions in the shell gets created everything is fine, the Application.Current property is of type "MyName.Shell.App". But when a view gets added after startup, as a response to user input, the Application.Current type is suddenly of type "Application", and thus the IsInDesignMode method returns true and the regions are not created.

If I remove the Application.Current conditions everything works as expected. So the question is, is there something wrong in my application or is there something wrong in the prism source code?

Aug 12, 2010 at 5:21 PM

I asked Larry (our test lead) to see if he could reproduce this issue, and he was able to do so using Prism v2.2.  He is doing a bit more investigation to see if it still exists in the v4 code we currently have and to track down the root issue. 

In the meantime, if changing the code as you mentioned works, do it and keep an eye out for a fix in the next v4 drop.

Michael Puleio

Aug 13, 2010 at 11:33 PM

I have an update.  After looking at the sample app that was written based on your description, I found a bug in the sample and we were not able to reproduce your problem after all. 

I updated the Issue ( and attached the sample app that we created to test this out.  Please take a look and let me know what you see that is different between the sample and what you have written to help us figure out the issue you are running into.

Michael Puleio

Aug 16, 2010 at 3:36 PM

I have updated the Issue ( and attached a modified sample ( where my problem occurs.

Aug 17, 2010 at 4:21 PM

I'll look at it (or have someone else from the team do so) as soon as I can.


Aug 17, 2010 at 9:29 PM

Hmmmmm.  It looks like the behavior of a few things changed in SL4.

For the moment, hack your version of RegionManager.IsInDesignMode() to look like this:

private static bool IsInDesignMode(DependencyObject element)
  return DesignerProperties.GetIsInDesignMode(element);

We're going to investigate fixes and try to determine if the known issue from Cider (that caused the current implementation of IsInDesignMode to be written) has been fixed.. 

The fix won't make the next drop, but we'll get it figured out soon.

Michael Puleio