Search code examples
c#wpfprism

When would a Prism region have more than one active view simultaneously?


I'm a little confused about something with Prism. Each time I navigate my main region to a different view and I handle the PageNavigationCompleted event, I check the list of active views for the region.

var views = RegionManager.Regions[Regions.Main].ActiveViews.ToList();

And every single time the list returned contains one and only one view: The view I just navigated to. No matter how many times I navigate or how many different types of views I navigate to, the list holds at most, one item. (This jibes with my experience implementing IActiveAware in my view-models. When Prism sets one view-model's IsActive property to true it sets another's to false.)

Currently, my code assumes that the first view in the list of active regions is THE active view. Because so far, it always has been.

But if there were always only at most one view active per region, then why would active regions be a list and not just a single object reference?

There must be scenarios in which the list of active views for a region contains more than one, right? Can anyone tell me what that scenario might be? Even visually, what sort of layout is that?


Solution

  • It depends on the control that hosts the region, and on the type of the IRegion instance which is derived from that by the RegionAdapter used. A ContentControl, for example, can only host one view at a time, obviously.

    An ItemsControl, though, hosts all its views (i.e. items) at the same time.