在 Shell.xaml 中创建区域期间的 KeyNotFoundException

Son*_*y D 1 wpf prism

我刚开始使用 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>
Run Code Online (Sandbox Code Playgroud)

.

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

运行后我得到异常:

KeyNotFoundException:未在区域适配器映射中注册 System.Windows.Controls.Grid 类型的 IRegionAdapter。您可以通过覆盖引导程序中的 ConfigureRegionAdapterMappings 方法来为此控件注册 IRegionAdapter。

AutofacBootstrapper好的,但是类没有任何命名ConfigureRegionAdapterMappings为覆盖的方法。

首先我认为有问题AutofacBootstrapper,但即使我将其更改为UnityBootstrapper问题仍然存在。但是第二个允许我覆盖ConfigureRegionAdapterMappings

Hau*_*ger 6

AGrid不是区域的有用主机。尝试使用 aContentControl代替。

当然,如果您绝对想使用 ,您可以创建和注册自定义区域适配器Grid,但我看不出有什么好处。