私は自分のオフィス用のアプリケーションとして、プリズム付きWPFを使用しています。私はロードブロッキングを打ちました。私はこのアプリでやるべきことのいくつかをやっていたBrian Lagunas(プリズムの開発者の一人)が主催するウェブセミナーを見つけました。私は基本的に私のアプリに合わせて名前空間などを変更しました。プロパティ 'Prism.Regions.RegionManager.RegionName'の設定が例外をスローしました
ソリューションはコンパイルされますが、ContentControl with Prism:RegionManager.RegionNameを使用してナビゲートしようとすると、例外がスローされます。
解決策には2つのプロジェクトがあります。最初のプロジェクトは2番目のプロジェクトのMainWindowを呼び出します。私のコードは以下の通りです。
プロジェクト1 - プロジェクト2メインページのメインウィンドウ
namespace AdjusterToolV2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private void btnLetters_Click(object sender, RoutedEventArgs e)
{
URLetters.MainWindow frm1 = new URLetters.MainWindow();
frm1.Show();
}
}
}
プリズムブートストラップ
using Prism.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Practices.Unity;
using URLetters.Views;
namespace URLetters
{
public class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType(typeof(object), typeof(PHLtrWithEvidenceView), "PHLtrWithEvidenceView");
}
}
}
XAML(コードが後ろ空である)
<Controls:MetroWindow x:Class="URLetters.MainWindow"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:local="clr-namespace:URLetters"
mc:Ignorable="d"
Title="Unresolved Liability Letters"
Height="500"
Width="700"
Icon="../Resources/GEICO.ico"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" Background="#154995" HorizontalAlignment="Left" LastChildFill="False" Width="120">
<StackPanel Grid.Column="0">
<Button x:Name="btn48hrWithEvidence"
Command="{Binding NavigateCommand}"
CommandParameter="PHLtrWithEvidenceView"
x:FieldModifier="public"
Height="40"
Width="100"
Margin="10,10,0,0"
ToolTip="Letter to the PH with a 48 hour contact time limit. Used when evidence has been provided by the claimant" >
<TextBlock FontSize="11" Text="48 Hour - PH With Evidence" TextWrapping="Wrap" TextAlignment="Center" />
</Button>
<Button x:Name="btn48hrNoEvidence"
Height="40"
Width="100"
Margin="10,10,0,0"
ToolTip="Letter to the PH with a 48 hour contact time limit. Used when there is no evidence provided by the claimant" >
<TextBlock FontSize="11" Text="48 Hour - PH With No Evidence" TextWrapping="Wrap" TextAlignment="Center" />
</Button>
<Button x:Name="btnNoCtcPH"
Height="40"
Width="100"
Margin="10,10,0,0"
ToolTip="Letter to the PH advising them that we have reached an AT FAULT liability decision based on the evidence provided." >
<TextBlock FontSize="11" Text="No Contact - PH Liability Decision" TextWrapping="Wrap" TextAlignment="Center" />
</Button>
<Button x:Name="btnNoCtcPHLiabDenial"
Height="40"
Width="100"
Margin="10,10,0,0"
ToolTip="Letter to the PH advising them that we have denied liability because we have no evidence to support the PH involvement" >
<TextBlock FontSize="11" Text="No Contact - PH Liability Denial" TextWrapping="Wrap" TextAlignment="Center" />
</Button>
<Button x:Name="btnNoCtcCLMTLiabDenial"
Height="40"
Width="100"
Margin="10,10,0,0"
ToolTip="Letter to the CLAIMANT advising that we have denied liability because we have no evidence to support the PH involvement" >
<TextBlock FontSize="11" Text="No Contact - CLMT Liability Denial" TextWrapping="Wrap" TextAlignment="Center" />
</Button>
</StackPanel>
</DockPanel>
<DockPanel x:Name="ContentRegionName" Grid.Column="1">
<ContentControl prism:RegionManager.RegionName="ContentRegion"/>
</DockPanel>
</Grid>
</Controls:MetroWindow>
ビューモデルプロジェクト2メインウィンドウ
用using Prism.Mvvm;
using Prism.Regions;
using Prism.Commands;
namespace URLetters.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private readonly IRegionManager _regionManager;
public DelegateCommand<string> NavigateCommand { get; set; }
public MainWindowViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;
NavigateCommand = new DelegateCommand<string>(Navigate);
}
private void Navigate(string uri)
{
_regionManager.RequestNavigate("ContentRegion", uri);
}
}
}
それは、この行のXAMLファイルで例外がスローされます。
<ContentControl prism:RegionManager.RegionName="ContentRegion"/>
例外が読み:「例外がスローさ:PresentationFramework.dll
の 'System.Windows.Markup.XamlParseException'追加情報: 'プロパティ' Prism.Regions.RegionManager.RegionName 'を設定すると例外がスローされました。行番号「69」および行位置「14」。
これは、[btnLetters]ボタンをクリックすると発生します。 URLetters MainWindowが開かず、例外がスローされます。私はコードを振り返って、ウェビナーの例と照らし合わせてチェックしましたが、なぜ例外がスローされているのか理解できません。
ああ、忘れていた。私は、次のNuGetパッケージが以前インストールがあります。 プリズムコア6.2 プリズムユニティ6.2 プリズムWPF 6.2 MahApps.Metroのために1.2.4 ユニティ4.0.1 –