views:

1422

answers:

2

I'm using the Composite Application Guidelines (Version 2, Feb 2009).

I've built the Shell with one region, a Bootstrapper and an Employee Module with two views, both of which I want the RegionManager to add to one region in the shell.

However, only the last view added to the RegionManager is displayed in the region.

What do I need to change so that both views are shown in the Shell's region?

namespace EmployeeModule
{
    public class EmployeeModule : IModule
    {
        private readonly IRegionManager _regionManager;

        public EmployeeModule(IRegionManager regionManager)
        {
            _regionManager = regionManager;
        }

        public void Initialize()
        {
            _regionManager.RegisterViewWithRegion(Infrastructure.RegionNames.MainRegion, typeof(Views.EmployeesView.EmployeesView));
            _regionManager.RegisterViewWithRegion(Infrastructure.RegionNames.MainRegion, typeof(Views.EmployeesListView.EmployeesListView));
        }
    }
}
A: 

Allow me to answer my own question:

The above RegionManager code works fine.

You have to take the width and height properties off of the UserControl element in your views, otherwise they cover each other up.

Edward Tanguay
A: 

Well, I'm not sure your solution is not exactly correct; it's definitely ugly. I believe the problem you are running into is that you are marking a Grid or a Canvas as a region. This is fine, but the elements will cover themselves up in those cases unless you are able to specify X and Y offsets for a Canvas or Column/Row for a Grid.

Prism provides three types of adapters for regions. See MSDN.

  1. ContentControlRegionAdapter. This adapter adapts controls of type System.Windows.Controls.ContentControl and derived classes.
  2. SelectorRegionAdapter. This adapter adapts controls derived from the class System.Windows.Controls.Primitives.Selector, such as the System.Windows.Controls.TabControl control.
  3. ItemsControlRegionAdapter. This adapter adapts controls of type System.Windows.Controls.ItemsControl and derived classes.

What this means is that you can use regions on top of any ContentControl (controls that display one Content element), Selectors, that display multiple content elements and have a concept of a selected item, and ItemsControl, which is just a control that displays multiple objects.

I believe the solution to your problem is then to use the ItemsControl, which will automatically size itself to display all your Views.

siz