How to register views for navigation

I have a project structure as follows:

Modules --- ModuleA ---ViewA ---ViewModelA ---Module --- ModuleB ---ViewB ---ViewModelB ---Module MyApplication ---Shell.xaml ---Bootstrapper MyApplication.Infrastructure --- --- 

Now, in the module Module.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)); } } 

Now, in the module Module.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> 

In 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)); } 

When I launch the application, I get an error message indicating that no export or multiple export was found for ContentRegion. I can understand that I am registering both my submissions in the same region, so I get this error.

But I don’t know how to register my views for navigation purposes, so when I click on MenuItem Show View A , ViewA should appear in the content area. Similarly for ViewB.

0
source share
1 answer

Have you tried reading the documents?

https://github.com/PrismLibrary/Prism/blob/master/Documentation/WPF/60-Navigation.md#prism-region-overview

Using MEF, you can simply export the view type with the specified name.

 [Export("InboxView")] public partial class InboxView : UserControl 
+2
source

Source: https://habr.com/ru/post/903478/


All Articles