WPFにおけるPrism集中講座(3) 試しにViewのサンプルを書いてみる
プロジェクトの下準備 まず、MainWindow からメニューで「設定」を開いて、設定画面から「設定終了」ボタンで MainWindow に戻るサンプルです。 新規ソリューションを「WPFアプリケーション」で作成します。.NET 9 を利用すれば良いでしょう。 ここでは SimplePrismViewSample という名前にしています。 そして、NuGet から Prism.Unity をインストールします。自分は Visual Studio の NuGet 管理から入れていますが、dotnet 等を扱える人に、改めての説明は不要でしょう。 App.xaml 周辺の設定 Views の設定 ソリューションエクスプローラで Views フォルダを作り、MainWindow.xaml を Views フォルダに移動します。 デフォルトのソリューション直下に MainWindow.xaml を置いていたら、以下の書き換えでエラーを吐きます。 …一体どこに Views が含まれてるんですかね?ブラックボックス臭い… MainWindow.xaml の修正 <Window x:Class="SimplePrismViewSample.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/" Title="SimplePrismViewSample" Width="525" Height="350"> <Grid> <ContentControl prism:RegionManager.RegionName="ContentRegion" /> </Grid> </Window> MainWindow.xaml の位置を移動したので、x:Class="SimplePrismViewSample.MainWindow" を x:Class="SimplePrismViewSample.Views.MainWindow" に書き換える必要があります。 App.xaml の記述 App.xaml を以下のように書き換えます。 <prism:PrismApplication x:Class="SimplePrismViewSample.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SimplePrismViewSample" xmlns:prism="http://prismlibrary.com/"> <Application.Resources /> </prism:PrismApplication> App.xaml.cs の記述 App.xaml.cs を以下のように書き換えます。 ...