【发布时间】:2018-01-17 09:26:59
【问题描述】:
我希望我的模块按需加载,因为我有一个困惑,如果我们不打算最初初始化我们的模块,那么在加载之后我们可以如何以及在哪里编写代码来执行和加载模块。 作为参考,我尝试过的只是将 ShellViewModel 代码放在这里。 请让我知道我还需要做什么才能加载按需视图,或者如果您有任何好的演示参考,请告诉我
public class ShellViewModel
{
public ShellViewModel(IModuleEnumerator moduleEnumerator, IModuleLoader moduleLoader, IRegionManager regionManager)
{
this.Initialize(moduleEnumerator, moduleLoader, regionManager);
}
public ICommand LoadModuleA { get; set; }
public ICommand LoadModuleB { get; set; }
public IModuleLoader ModuleLoader { get; set; }
public IModuleEnumerator ModuleEnumerator { get; set; }
public IRegionManager RegionManager { get; set; }
private void Initialize(IModuleEnumerator moduleEnumerator, IModuleLoader moduleLoader, IRegionManager regionManager)
{
// Initialize command properties
this.LoadModuleA = new LoadModuleACommand(this);
this.LoadModuleB = new LoadModuleBCommand(this);
// Initialize module properties
this.ModuleEnumerator = moduleEnumerator;
this.ModuleLoader = moduleLoader;
this.RegionManager = regionManager;
}
}
}
下面是引导类
public class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
var shell = Container.Resolve<Shell>();
var shellViewModel = Container.Resolve<ShellViewModel>();
shell.DataContext = shellViewModel;
shell.Show();
return shell;
}
protected override IModuleEnumerator GetModuleEnumerator()
{
return new DirectoryLookupModuleEnumerator(@".\Modules");
}
}
如果需要发布更多代码,请告诉我我无法知道如何按需加载模块以及实际代码需要在哪里编写(即在哪个部分)
【问题讨论】: