简体   繁体   中英

How to add views to an itemscontrol in Prism with MEF and WPF

I have an application which, so far has only 2 views. View 1 is a list and the second is a detail view (once you've selected an item in view 1.

I've set up a region in my Prism shell and can get my modules loaded. What I want is for only module 1 to load initially. When I've selected an item from 1 then I want to navigate to 2 (which would then show up in my itemscontrol (which, by the way, is a tab control).

Problem I have is that I either get a) both views show initially in my tab control.

b) If I change the export attribute on view b's module to initialise on demand, when I click to navigate to view b nothing happens.

Any help would be much appreciated. Thanks.

I have got around this by letting all the views be discovered but on initalisation of the view I deactivate all views accept the one I'm interested in. Of course I'm looking for a better way :)

foreach (var view in RegionManager.Regions["RegionFoo"].Views)
{
  if (view.GetType() == initialViewType)
  {
     RegionManager.Regions["RegionFoo"].Activate(view);
  }
  else
  {
     RegionManager.Regions["RegionFoo"].Deactivate(view);
  }
}

I do this after the views have been registered for disovery in that region. initialViewType is the type of view you wish to find. This assumes only a singleton of the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM