Welcome

首页 / 软件开发 / .NET编程技术 / Composite Application Guidance for WPF(4)——Bootstrapper

Composite Application Guidance for WPF(4)——Bootstrapper2012-02-07 博客园 周银辉在默认情况下,WPF程序的启动方式APP的XAML中指定StartUri,然后IDE会自动帮我们生成一个Main方法,然后将StartUri中指定的窗口New一个出来,并作为应用程序的主窗口,但我们在Composite Application Guidance for WPF(3)——创建第一个Composite WPF Application(如果你不了解Prism的启动方式,那么建议你阅读) 中改变了这种方式:

    public App()    {      var boot = new Bootstrapper();      boot.Run();    }
而Bootstrapper类似于这样的类型:

  class Bootstrapper : UnityBootstrapper  {    protected override DependencyObject CreateShell()    {      var shell = new Shell();      shell.Show();      return shell;    }    protected override IModuleEnumerator GetModuleEnumerator()    {      var configStory = new ConfigurationStore();      var enumerator = new ConfigurationModuleEnumerator(configStory);      return enumerator;    }  }
其中这里的Shell实质上是我们应用程序的主窗口,可以看出来,其是在CreateShell()方法中将主窗口显示出来的,为什么要这样呢,那么我们就来看看Prism中的Bootstrapper