1、App.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
2、bootstrapper.Run(); 触发 初始化 Bootstrapper UnityBootstrapper容器
class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.TryResolve<MainWindow>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)this.Shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule));
}
}
3、moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule)); 触发
public class HelloWorldModule : IModule
{
private readonly IRegionViewRegistry regionViewRegistry;
public HelloWorldModule(IRegionViewRegistry registry)
{
this.regionViewRegistry = registry;
}
public void Initialize()
{
regionViewRegistry.RegisterViewWithRegion("MainRegion", typeof(Views.HelloWorldView));
}
}
4、shell.xaml
<Window x:Class="HelloWorld.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/prism"
Title="Hello World" Height="300" Width="300">
<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />
</Window>
regionViewRegistry.RegisterViewWithRegion("MainRegion", typeof(Views.HelloWorldView));与 <ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />