【发布时间】:2018-07-27 15:31:52
【问题描述】:
我刚开始使用 PRISM,遇到了一个我无法解决的异常。
<Window x:Class="Workplace.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://www.codeplex.com/prism"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid Name="Header" prism:RegionManager.RegionName="Header">
</Grid>
</Grid>
</Window>
.
using Autofac;
using Prism.Autofac;
using Prism.Modularity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Workplace
{
class Bootstrapper : AutofacBootstrapper
{
protected override DependencyObject CreateShell()
{
return new Shell();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Window) this.Shell;
Application.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
}
}
}
运行后出现异常:
KeyNotFoundException:该类型的 IRegionAdapter System.Windows.Controls.Grid 未在区域适配器中注册 映射。您可以通过以下方式为此控件注册一个 IRegionAdapter 覆盖中的 ConfigureRegionAdapterMappings 方法 引导程序。
好的,但是 AutofacBootstrapper 类没有任何名为 ConfigureRegionAdapterMappings 的方法可以覆盖。
首先我认为AutofacBootstrapper 有问题,但即使我将其更改为UnityBootstrapper,问题仍然存在。但是第二个允许我覆盖ConfigureRegionAdapterMappings
【问题讨论】: