Problem getting the view from region

Topics: Prism v4 - Silverlight 4
Jun 2, 2011 at 10:51 AM
Edited Jun 2, 2011 at 10:56 AM

Hi,

I'm loading the module dynamically, using "modulemanger.LoadModule()". After loading the module in the region. I can't get the view from specified region.

Here is the code I used to get the view:

Load Module code

 

private void LoadOnDemandModule(string ModuleName,string ViewName, string RegionName)
        {
            var moduleInCatalog = _moduleCatalog.Modules.SingleOrDefault(m => m.ModuleName.Equals(ModuleName,StringComparison.CurrentCultureIgnoreCase));
            if (moduleInCatalog != null)
            {
                if (moduleInCatalog.State == ModuleState.NotStarted)
                {
                    _moduleManager.LoadModule(moduleInCatalog.ModuleName);
                }
                else
                {
                    _regionManager.RequestNavigate(RegionName,ViewName);
                }
                   
            }

          
           
        }

 

Getting View:

var fltView = _regionManager.Regions[_regionName].Views.SingleOrDefault();

Please let me know where I'm wrong.

Regards

Mahesh

 

 

Jun 2, 2011 at 3:14 PM

Hi Mahesh,

The reason you can’t obtain the view from the Views collection might be related to the fact that this method throws an exception if there is more than one element in the sequence.

On the other hand since the Views collection implements IEnumerable, you could iterate it via a foreach statement, or the FirstOrDefault method, as well as any other means of iterating an IEnumerable, and in that case obtain the view you are requesting.

Additionally, if your view is exported as a shared instance (a singleton), you could obtain it using the ServiceLocator.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic