我只是在学习 WPF 和 Caliburn.Micro。我正在关注此处提供的代码: http ://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper&referringTitle=Documentation
显然,此代码适用于 Silverlight,但我的项目是 WPF,因此我收到未定义 CompositionHost 的错误。
文档说我需要直接在 wpf 中初始化容器,但是没有文档说明如何。如何直接初始化容器?
编辑 1 引导程序在文档中是这样的:
container = CompositionHost.Initialize(
new AggregateCatalog(
AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
)
);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(container);
container.Compose(batch);
我将其转换为:
var catalog =
new AggregateCatalog(
AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
this.container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(this.container);
this.container.Compose(batch);
但是当我运行应用程序时,我收到 MEF 找不到 IShell 实现的错误
Could not locate any instances of contract IShell.
我相信我对 MEF 的初始化不正确。你能帮我修一下吗?