Using PRISM, how do I display the view from another module, and access its properties to update its state?

StackOverflow https://stackoverflow.com/questions/2342256

  •  23-09-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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&id=105

OTHER TIPS

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>(); 
     });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top