Silverlight 5 Navigation Project/Prism Navigation Cache Mode Disabled

Topics: Prism v4 - Silverlight 4
Dec 22, 2012 at 1:06 AM


I am using a Silverlight Navigation project with Prism. I am loading a module for a page and another module within the page. Everything works fine except for one thing.

If I set the Navigation Cache Mode to Enabled, the project works properly when I switch to the page. Everything loads and all modules are fully functional. I can switch to other pages in the application and back to the Prism Module page.

The problem is that I do not want to enable the page cache for the page. If I set the cache to disabled, then a white page appears instead of the module page. There are no errors and I have single-stepped through the code and it looks like everything is functioning properly.

Any ideas as to what might be wrong? I am assumming that page cache disabled is valid for Prism. Is this assumption correct? I have not found anything to the contrary on the Internet.

Thanks, Warren

Dec 26, 2012 at 5:34 PM

Hi Warren,

Based on my understanding of the aforementioned scenario, I believe that a possible cause of your problem could be that if you set the NavigationCacheMode to Disabled, a new instance of the page will be created for each visit to the page and if this page contains a Prism region defined in it, an exception may occur when navigating to it as Prism doesn't allow to register the same region more than once.

As a starting point I believe you could subscribe to the Frame NavigationFailed Event to check if an exception is being swallow. By checking the EventArgs passed in the event handler you could find more information if an exception is being thrown, which could be helpful to find the cause of this behavior.

I hope you find this handy,

Agustin Adami

Dec 27, 2012 at 2:32 PM

Hello Agustin,

Thanks for your assistance. I have already subscribed to the ContentFrame_NavigationFailed method in the Shell. The failure does behave like an exception has occurred, but I have not been able to trap the event in my try/catch blocks.

I do have two levels of Prism modules being loaded in this case. After the main prism module for the page is loaded, 1 of N sub-modules is conditionally loaded based upon user choices that occur prior to loading the main prism module.

Is setting the NavigationCacheMode to Disabled not supported with Prism? In other words, is the Module Manager incapable of dealing with my stated two-tier module Page scenario by design?

If the above configuration is not supported in Prism, then the second issue, no visible exception thrown, is probably a mute point. Although, I would like to figure out what is masking the apparent exception which produces the white screen of death.

Thanks, Warren

Dec 27, 2012 at 4:11 PM


I did some additional testing and I have a guess as to what is happening. Can you please confirm or reject my hypothesis.

I normally have the following code inline with the module load code.

if (module != null && module.State == ModuleState.NotStarted)


The second time the page is loaded, the module state is initialized, which means the module will not be loaded due to the conditional logic above. If the page is not cached, then it appears that the Silverlight Navigation page does not know what to load so it is blank.

When I altered the above code to the following, the result is the same.

if (module != null)


It appears that the module manager is smart enough to know that the module is already loaded and initialize, hence it does nothing (i.e., does not load a module or throw an exception). It would appear that it does not think anything is wrong.

The page load result is the same in that the Navigation template has nothing to display because nothing is loaded.

Does this possibly explain what is happening. I.e., things are actually working correctly?

Thanks, Warren

Dec 27, 2012 at 6:22 PM

Hi Warren,

Based on your additional information, it seems that the fact you are trying to load a module more than once could be related to your problem. Take into account that in Prism modules are not intended to be loaded more than once (you could find more information about this in the Modular Application Development Chapter of the documentation).

As you mentioned calling the LoadModule method for the second time won't throw an exception, neither it will call the Initialize method again. However, after you have loaded a module, the view and all the components defined in it will be available to the main application. Therefore you may have to define some logic to react accordingly in case your module has already been loaded, and perform the necessary updates as required (like changing the state of your views). This can be achieved in several ways, for example in my opinion a possible approach could be by using the Event Aggregator. This way once you ensure the module has been loaded, you could publish an event that was subscribed in it, and define the necessary logic in the handler of this event to perform the updates, for example injecting a view in the corresponding region, allowing to reuse this logic without depending on the modules' Initialize method.

Additionally, if you are interested, you could find more information on how to publish and subscribe to events using the Event Aggregator in the following chapter:

I hope this helps,

Agustin Adami

Dec 28, 2012 at 12:45 PM

Hello Agustin,

Thanks for your tips.

It looks like all that is required is to detect when the module in ‘Initialized’ and then to drop in the appropriate initialization and view visibility code. Something like the following:

if (module != null && module.State == ModuleState.NotStarted)


else if(module != null && module.State == ModuleState.Initialized)


Initialization and visibility code here…


I have already implemented a common event service to allow inter-module/code block communication. I was able to get an instance of the page/module view and set its visibility attribute, which eliminated the white screen. It works just like the cache is enable. I have not implemented the publish/subscribe initialization event yet, but that should be straight forward through my existing messaging/event system.

I appreciated your help.