Search code examples
c#mvvmc#-4.0prismprism-4

How to get the list of Regions in the RegionManager in PRISM?


I'v got the following code :

public class MyModule: IModule { private IRegionManager mRegionManager { get; set; }

    public CMBaseTable(IRegionManager regMan)
    {
        mRegionManager = regMan;
    }

    public void Initialize()
    {
        mRegionManager.RegisterViewWithRegion("MainRegion",typeof(MyView));
        var vs = mRegionManager.Regions["MainRegion"].Views;//<--- I get an exception here
    }
}

In the line

var vs = mRegionManager.Regions["MainRegion"].Views;

I'll get an exception that says: KeyNotFoundException : "The region manager does not contain the MainRegion region."

But I'm sure that MainRegin is defined and other modules have added views in it.


Solution

  • You can always take a look into the source. RegionCollection implements IEnumarable so you can iterate over the collection or you can simply use the provided function public bool ContainsRegionWithName(string regionName).