のためのビューを登録する方法:次のように私は、プロジェクトの構造を持っているナビゲーション
Modules
--- ModuleA
---ViewA
---ViewModelA
---Module
--- ModuleB
---ViewB
---ViewModelB
---Module
MyApplication
---Shell.xaml
---Bootstrapper
MyApplication.Infrastructure
---
---
を今、ModuleA.Moduleで:
[ModuleExport(typeof(Module), InitializationMode = InitializationMode.WhenAvailable)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class Module : IModule
{
IRegionManager _regionManager;
[ImportingConstructor]
public Module(IRegionManager regionManager)
{
_regionManager = regionManager;
}
public void Initialize()
{
_regionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(ViewA));
}
}
を今、ModuleB.Moduleで:
[ModuleExport(typeof(Module), InitializationMode = InitializationMode.WhenAvailable)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class Module : IModule
{
IRegionManager _regionManager;
[ImportingConstructor]
public Module(IRegionManager regionManager)
{
_regionManager = regionManager;
}
public void Initialize()
{
_regionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(ViewB));
}
}
In Shell.xaml:
<DockPanel LastChildFill="True">
<Menu DockPanel.Dock="Top">
<MenuItem Header="Show View A" />
<MenuItem Header="Show View B" />
</Menu>
<ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.ContentRegion}"/>
</DockPanel>
Bootstrapper.cs
で
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BootStrapper).Assembly));
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(RegionNames).Assembly));
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleA.Module).Assembly));
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleB.Module).Assembly));
}
私はアプリケーションを実行すると、私は輸出または複数の輸出がContentRegion見つかりませんでしたことを指定するエラーを取得します。私は同じ地域に両方の意見を登録していることを理解できます。そのエラーが発生します。
しかし、ナビゲーション目的でビューを登録する方法がわからないので、MenuItem Show View A
をクリックすると、ViewAがコンテンツ領域に表示されます。 ViewBも同様です。
これは役立つかもしれない:http://stackoverflow.com/questions/35476745/how-to-register-modules-in-prism-6-wpf-application-with-view-switching-navigatio –
@RリチャードはUnityを使用しています。私はMefを使いたい。 – Vishal
申し訳ありません。これについてはどうすればいいですか:http://stackoverflow.com/questions/33301926/wpf-prism-request-navigate-activation-error/33303082#33303082 –