WPFにおけるPrism集中講座(1) 序盤のサンプルについて
Prismについて 正直、この記事を読んでいる方には、今さら説明は不要でしょう。 特にこの記事はWPFを中心に書いているため、WPFとPrismといえばMVVMのためのライブラリ。そのPrismについて徹底解説をしていこうと思います。 PrismLibrary/Prism-Samples-Wpf 01-BootstrapperShell 正直、このサンプルに戸惑った人は多いのではないでしょうか? Descriptionoには Create a basic bootstrapper and shell と書かれています。 初期プロジェクトから書き換え、追記されているのは以下の通りです。 App.xaml <Application x:Class="BootstrapperShell.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:BootstrapperShell"> <Application.Resources /> </Application> App.xaml.cs using System.Windows; namespace BootstrapperShell { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var bootstrapper = new Bootstrapper(); bootstrapper.Run(); } } } MainWindow.xaml <Window x:Class="BootstrapperShell.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Shell" Width="525" Height="350"> <Grid> <ContentControl Content="Hello from Prism" /> </Grid> </Window> Bootstrapper.cs using System.Windows; using BootstrapperShell.Views; namespace BootstrapperShell { class Bootstrapper : PrismBootstrapper { protected override DependencyObject CreateShell() { return Container.Resolve<MainWindow>(); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { } } } ざっくり言うと App.xaml.cs から Bootstrapper インスタンスを生成して、それを走らせ Run するわけですね。 で Bootstrapper.cs では PrismBootstrapper という、よく分からないブートストラッパが継承されています。 ...