Reputation: 429
I want to navigate from ModuleA View to ModuleB View. How can I implement navigation between modules?
In my application which uses Prism framework, I have two module
I configure two modules in my Bootstrapper like this:
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
moduleCatalog.AddModule(typeof(ModuleA));
moduleCatalog.AddModule(typeof(ModuleB));
}
I register my both Views in my ModuleA and ModuleB like this:
public class ModuleA : IModule
{
private readonly IRegionManager regionManager;
private readonly IUnityContainer container;
public StaffModule(IUnityContainer container, IRegionManager regionManager)
{
this.container = container;
this.regionManager = regionManager;
}
public void Initialize()
{
this.regionManager.RegisterViewWithRegion("MainRegion", () => this.container.Resolve<StaffView>());
}
}
public class AccountModule : IModule
{
private readonly IRegionManager regionManager;
private readonly IUnityContainer container;
public AccountModule(IUnityContainer container, IRegionManager regionManager)
{
this.container = container;
this.regionManager = regionManager;
}
public void Initialize()
{
container.RegisterType<object, AccountView>("AccountView");
////this.regionManager.RegisterViewWithRegion("MainRegion", () => this.container.Resolve<AccountView>());
}
}
When I click Button from StaffView in ModuleA, I want to navigate to AccountView in ModuleB. Here is my code for navigation.
private void LodeViewfromModule()
{
IUnityContainer unityContainer = ServiceLocator.Current.GetInstance<IUnityContainer>();
var regionManager=unityContainer.Resolve<IRegionManager>();
var uri = new Uri("pack://application:,,,/PrismAuto.Account;component/AccountView.xaml", UriKind.RelativeOrAbsolute);
regionManager.RequestNavigate("MainRegion", uri);
}
But it shows:
System.Object exception.
Please, anyone help me to solve this problem.
Upvotes: 0
Views: 1505
Reputation:
You are registering your view for navigation using:
container.RegisterType<object, AccountView>("AccountView");
and navigating to it like:
var uri = new Uri("pack://application:,,,/PrismAuto.Account;component/AccountView.xaml", UriKind.RelativeOrAbsolute);
regionManager.RequestNavigate("MainRegion", uri);
This is wrong. You need to navigate to it using the key your provided when you registered it for navigation:
regionManager.RequestNavigate("MainRegion", "AccountView");
Also, if you are using Prism 6 there is an extension method in the Prism.Unity namespace for registering your views for navigation like this:
container.RegisterTypeForNavigation<AccountView>();
Upvotes: 5