我的shell窗口中有一组选项卡,一个主要区域whicxh是contentcontrol.我还有四个模块,我想在选择某个选项卡时按需加载.因此,当选择tab1时,我想加载moduleA,当选择tab2时,我想加载ModuleB等.第一个模块在应用程序启动时加载.问题是当我改变标签时没有任何反应.没有错误很难.我正在使用这个版本的棱镜复合应用指南WPF和Silverlight - 2009年10月.
我试过这种方法:
贝壳:
public partial class Shell : RibbonWindow, IShellView { private readonly IRegionManager regionManager; private readonly IModuleManager moduleManager; public Shell(IModuleManager moduleManager) { this.moduleManager = moduleManager; InitializeComponent(); } public void ShowView() { this.Show(); } private void onTabSelection(object sender, RoutedEventArgs e) { this.moduleManager.LoadModule("ModuleB"); } }
引导程序:
public partial class MyBootstrapper : UnityBootstrapper { protected override IModuleCatalog GetModuleCatalog() { var catalog = new ModuleCatalog(); catalog.AddModule(typeof(ModuleA)).AddModule(typeof(ModuleB)); return catalog; } protected override void ConfigureContainer() { Container.RegisterType(); base.ConfigureContainer(); } protected override DependencyObject CreateShell() { ShellPresenter presenter = Container.Resolve (); IShellView view = presenter.View; view.ShowView(); return view as DependencyObject; } }
而且我希望能够按需加载的moduleB(我以前使用这条注释行,这就是我把它留在这里的原因):
[Module(ModuleName = "ModuleB", OnDemand = true)] public class ModuleB : IModule { private readonly IUnityContainer _container; private readonly IRegionManager _regionManager; public ModuleB(IUnityContainer container, IRegionManager regionManager) { _container = container; _regionManager = regionManager; } public void Initialize() { _regionManager.Regions["MainRegion"].Add(new ModuleBView()); this.RegisterViewsAndServices(); // this._regionManager.RegisterViewWithRegion(RegionNames.MainRegion, () => _container.Resolve()); } protected void RegisterViewsAndServices() { _container.RegisterType (); } }
我在这做错了什么?我该怎么办?