Dynamic Loading and UI

Topics: Prism v2 - Silverlight 3
Aug 28, 2009 at 8:41 PM

Hey All,

A simple problem that I'm sure there is a dumb answer for: when you are dynamically loading a module into a region is there some way to know when the module has started and stopped loading? I can think of ways to do it publishing events, etc. But is there a pre-baked solution to this, something like the Activity Control but for Prism regions?

Aug 31, 2009 at 6:28 PM


If I understand your scenario correctly, you want to be able to get notification when a particular module is loaded. Although this behavior does not come with Prism out of the box, you can implement it for your application. The following thread deals with that scenario:

Remember that you load views, which are part of modules, into regions not modules directly. If you want to get notification about a view being added to a region you can use the region's events.

Please let me know if this helps.

Damian Schenkelman

Sep 3, 2009 at 10:59 PM

Hi Damian,

Thanks for your reply! You are correct I'm just concerned with the visual aspect of determining when a view is available to display to the user. You speak of region events; do you mean that the control (Content Control) has some events to determine if a view has been loaded or the IRegionManager has some events? If the later is the case could you point me in the direction where I can learn a bit more about this?




Sep 7, 2009 at 3:36 PM

Hi Luke,

When you talk about a view being available to display to the user I have two possible interpretations for it.

First: You want to know if the module that has a particular view has been loaded so you can add that view to a region. In Prism, there is no way to get notification that a module has been loaded. However, you can check that at a particular moment in your application by executing code like this:

ModuleInfo info = this.moduleManager.Modules.First<ModuleInfo>(m => m.ModuleName == "ModuleName");
            if (info.State == ModuleState.Initialized)
                //Views are ready

You must really consider when the above code should be used, since you might be tightly coupling your modules.

Second: You want to know when a view has been added to a region so it can be displayed. The IRegion Views property  exposes the Views.CollectionChanged event. This event will allow you to know when a view is added/removed to a particular region. So, if you add a view into a region (for example when your module is loaded), you will receive a notification through this event and be able to act upon it.

Please let me know if this helps.

Damian Schenkelman