在 Shell.xaml 中创建区域时出现 KeyNotFoundException
KeyNotFoundException during create region in Shell.xaml
我刚开始使用 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: The IRegionAdapter for the type
System.Windows.Controls.Grid is not registered in the region adapter
mappings. You can register an IRegionAdapter for this control by
overriding the ConfigureRegionAdapterMappings method in the
bootstrapper.
好的,但是 AutofacBootstrapper
class 没有任何名为 ConfigureRegionAdapterMappings
的方法可以覆盖。
首先我认为AutofacBootstrapper
有问题,但即使我将其更改为UnityBootstrapper
问题仍然存在。但是第二个允许我覆盖 ConfigureRegionAdapterMappings
A Grid
不是一个有用的区域主机。尝试改用 ContentControl
。
当然,如果您绝对想使用 Grid
,您可以创建并注册自定义区域适配器,但我看不出有任何好处。
我刚开始使用 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: The IRegionAdapter for the type System.Windows.Controls.Grid is not registered in the region adapter mappings. You can register an IRegionAdapter for this control by overriding the ConfigureRegionAdapterMappings method in the bootstrapper.
好的,但是 AutofacBootstrapper
class 没有任何名为 ConfigureRegionAdapterMappings
的方法可以覆盖。
首先我认为AutofacBootstrapper
有问题,但即使我将其更改为UnityBootstrapper
问题仍然存在。但是第二个允许我覆盖 ConfigureRegionAdapterMappings
A Grid
不是一个有用的区域主机。尝试改用 ContentControl
。
当然,如果您绝对想使用 Grid
,您可以创建并注册自定义区域适配器,但我看不出有任何好处。