01、BootstrapperShell

  1、将App.xaml中的StartupUri="MainWindow.xaml"删除。

  2、使用NuGet安装Prism.Wpf、Prism.Core、Prism.Unity。

  3、添加类“Bootstrapper”,编辑如下:

 1 using Microsoft.Practices.Unity;
 2 using Prism.Unity;
 3 using System.Windows;
 4 using BootstrapperShell.Views;
 5 
 6 namespace BootstrapperShell
 7 {
 8     public class Bootstrapper : UnityBootstrapper
 9     {
10         protected override DependencyObject CreateShell()
11         {
12             return Container.Resolve<MainWindow>();
13         }
14 
15         protected override void InitializeShell()
16         {
17             Application.Current.MainWindow.Show();
18         }
19     }
20 }

  4、创建文件夹Views,将MainWindow.xaml移动到此文件夹中。

    

  5、修改App.xaml

 1 using System.Collections.Generic;
 2 using System.Configuration;
 3 using System.Data;
 4 using System.Linq;
 5 using System.Threading.Tasks;
 6 using System.Windows;
 7 
 8 namespace BootstrapperShell
 9 {
10     /// <summary>
11     /// App.xaml 的交互逻辑
12     /// </summary>
13     public partial class App : Application
14     {
15         protected override void OnStartup(StartupEventArgs e)
16         {
17             base.OnStartup(e);
18 
19             var bootstrapper = new Bootstrapper();
20             bootstrapper.Run();
21         }
22     }
23 }

 

posted @ 2018-08-27 20:24  风中寻觅  阅读(286)  评论(0)    收藏  举报