02、Regions

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

  6、修改文件夹Views中的MainWindow.xaml,在Grid中添加<ContentControl prism:RegionManager.RegionName="ContentRegion"/>,      

    注意 xmlns:prism="http://prismlibrary.com/"

1 <Window x:Class="Regions.Views.MainWindow"
2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4         xmlns:prism="http://prismlibrary.com/"
5         Title="Shell" Height="350" Width="525">
6     <Grid>
7         <ContentControl prism:RegionManager.RegionName="ContentRegion"/>
8     </Grid>
9 </Window>

 

posted @ 2018-08-28 10:29  风中寻觅  阅读(402)  评论(0)    收藏  举报