Prism(一)框架使用
源码地址 - WineMonk/PrismStudy: Prism框架学习 (github.com)
引入prism框架
使用启动加载器
1 2 3 4 5 6 7 8 9 10
| public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e);
var bootstrapper = new Bootstrapper(); bootstrapper.Run(); } }
|
1 2 3 4 5 6 7 8 9 10 11 12
| class Bootstrapper : PrismBootstrapper { protected override DependencyObject CreateShell() { return Container.Resolve<MainWindow>(); }
protected override void RegisterTypes(IContainerRegistry containerRegistry) { } }
|
修改启动对象
App.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <!-- <Application x:Class="Regions.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Regions"> <Application.Resources /> </Application> --> <prism:PrismApplication x:Class="Regions.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Regions" xmlns:prism="http://prismlibrary.com/"> <Application.Resources /> </prism:PrismApplication>
|
App.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public partial class App : PrismApplication { protected override Window CreateShell() { return Container.Resolve<MainWindow>(); }
protected override void RegisterTypes(IContainerRegistry containerRegistry) { }
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { } }
|