Reputation: 273
I am using WPF Prism 6
with autofac
and having issues navigating between views. What I have is a view that I only want to keep alive till I leave it, and the next time I navigate to it, I want to create a new version of this view.
On load, I regist an IModule
that has the following code
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion,
typeof(DxfDisplay.Views.DxfDisplay));
This registers my view and the system works on initial load, I implement the INavigationAware
and IRegionMemberLifetime
interfaces on the view model and have public bool KeepAlive => false;
implementing the IRegionMemberLifetime
so that my view is disposed when I am done.
When I navigate away from this view everything is fine, but when I attempt to navigate to navigate to the view using
_regionManager.RequestNavigate(RegionNames.MainRegion,
new Uri("DxfDisplay", UriKind.Relative), parameters);
The view is not opened and a view model constructor is not called. To make the navigation work correctly, I need to register with view with the region again. Or if I change the KeepAlive to true
I can navigate back to the original view, but I cannot generate a new view if INavigationAware.IsNavigationTarget
returns false.
My question is how do I register the view with the region manager in such a way that when I call _regionManager.RequestNavigate
, it will create a new instance of the view and display it. I feel like I am missing something simple and just overlooking it.
Upvotes: 3
Views: 2250
Reputation: 35914
In Prism 7, this is now called RegisterForNavigation<T>()
and exists on the IContainerRegistry
interface.
For example, in your module:
public class MyModule : IModule
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<MyView>();
}
}
Upvotes: 0