tags:

views:

207

answers:

2

I have two modules, one is a Header module, one is a Items module.

I have a HeaderDetails view, which contains a region which is called 'ItemsSummaryRegion'. This region is registered to populate the region with the view ItemListView from the Items module.

regionManager.RegisterViewWithRegion("ItemsSummaryRegion", typeof(IItemListView));

The issue is, how do I get access to this automatically generated view so that I may set the list of Items it is supposed to display? I want to set this in the ViewModel of the HeaderDetails view.

Does anyone know how you do this? Or can suggest a better way of displaying this data?

Thank you.

A: 

You should use the unityContainer to create things and then call Add and Activate.

    public TaskList(IEventAggregator eventAggregator, 
                    IRegionManager regionManager, 
                    IUnityContainer container)
    {
        _EventAggregator = eventAggregator;
        _RegionManager = regionManager;
        _Container = container;
    }


        IItemListVM vm = _Container.Resolve<IItemListVM>();
        IItemListView view = new IItemListView(vm);

        _RegionManager.Regions["ItemsSummaryRegion"].Add(view);
        _RegionManager.Regions["ItemsSummaryRegion"].Activate(view);

This allows you to call IRegion.Remove later when you want to clear the region. If you just want to register a region with a view, you can do that too, just replace the last couple lines of my logic with the other call to RegisterViewWithRegion:

_RegionManager.RegisterViewWithRegion("ItemsSummaryRegion", 
     (x) => 
     { 
          _Container.Resolve<IItemListView>(); 
     });
thepaulpage
Thank you - I tried this solution first, however it threw an exception when trying to do this in the Constructor of the ViewModel because the region was not yet registered, how do I get around this?
James
You won't be able to call the register logic inside of the VM's constructor. You have to create one view before you can put another view inside of it. Be careful which view you're trying to show and where you're trying to show it.
thepaulpage
+1  A: 

If your two modules are so tightly coupled, wouldn't it make more sense to have just one module containing both views, and to set them up with master/detail.

This example shows something similar of what you are trying to achieve: http://www.tanguay.info/web/index.php?pg=codeExamples&amp;id=105

scim
This was my first impression as well. They are a logical Module.
Anderson Imes