對Prismv4和MEF有點新鮮。PRISM + MEF - 無法讓區域正常工作
我經歷了快速入門,並試圖將它們兩個結合在一起,但我似乎無法得到它的工作。
首先,我得到了一個Bootstrapper來加載Shell窗口。
public sealed class ClientBootstrapper : MefBootstrapper
{
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
//Add this assembly to export ModuleTracker (Shell is in this Assembly).
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
}
protected override DependencyObject CreateShell()
{
return Container.GetExportedValue<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Window)Shell;
Application.Current.MainWindow.Show();
}
}
這工作正常。顯示Shell窗口並出現一個很好的Hello World消息。然後我嘗試在Shell窗口中創建一個區域,以便可以將視圖加載到該區域。我甚至都沒有想到將它移到外部裝配上。
[ModuleExport(typeof(HelloWorldModule), InitializationMode = InitializationMode.OnDemand)]
public class HelloWorldModule : IModule
{
[Import(AllowRecomposition = true)]
private IRegionViewRegistry regionViewRegistry;
[ImportingConstructor()]
public HelloWorldModule(IRegionViewRegistry registry)
{
this.regionViewRegistry = registry;
}
public void Initialize()
{
regionViewRegistry.RegisterViewWithRegion("PrimaryRegion", typeof(Views.HelloWorldView));
}
}
了HelloWorld視圖(只是一個簡單的用戶控件,它包含一個TextBlock)沒有被加載到區域!我想我在這裏有點迷失在如何加載我的地區。
這篇文章的「答案」部分在哪裏? – 2011-04-27 14:43:43