问题描述:

I'm working in a project where I have declared two sections in the Shell; one of these is used to place a menu whose items will load modules on demand and the another one will be used to load the Views of the requested modules.

This is an example of the Shell design

 <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="1">

<Button Content="Home" Height="23" Name="Home" Width="75"/>

<Button Content="Users" Height="23" Name="Users" Width="75"/>

</StackPanel>

<Border Grid.Column="1" Grid.Row="1" Background="WhiteSmoke">

<ContentControl cal:RegionManager.RegionName="MainRegion" Name="MainRegion"/>

</Border>

As you can see the "Menu" is composed by button series (this is only for test) and a ContentControl that works like a Region where I need to load the Views.

This is an example of how is added the modules in my Bootstraper:

 protected override void ConfigureModuleCatalog()

{

base.ConfigureModuleCatalog();

System.Type homeModule = typeof(FieldCollection.Home.HomeModule);

ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;

moduleCatalog.AddModule(new ModuleInfo() { ModuleName = homeModule.Name, ModuleType = homeModule.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand });

System.Type userModule = typeof(FieldCollection.User.UserModule);

moduleCatalog.AddModule(new ModuleInfo() { ModuleName = userModule.Name, ModuleType = userModule.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand });

}

This is the Initialize method of the modules:

 public void Initialize()

{

this.container.RegisterType<IUserController, UserController>(new ContainerControlledLifetimeManager());

this.regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.UserSummaryView));

}

And finallly this is how the module is called from the menu.

 private void User_Click(object sender, RoutedEventArgs e)

{

moduleManager.LoadModule("UserModule");

}

The problem is that only the first view called is displayed in the region. I'm using Prism 4 and Unity like Dependency Injection container

Thanks for your help

网友答案:

ContentControl can only contain one item, use ItemsControl if you want multiple items to display within the same region.

LoadModule(String) will call the IModule.Initialize() method of the module only once and activate it at that point. Keep in mind that loading modules and viewing modules are not one in the same. Therefore if you call LoadModule(String) again it will not activate the views. A module and a view are not 1:1 relationships. A module can have multiple views associated with it.

What you could do instead is call

IRegionManager.Regions["MainRegion"].Activate(T);

...where T is an instance of the View you want to display.

相关阅读:
Top