Prism. OnNavigationTo doesn't fired when i show my view with RegisterViewWithRegion
I have a little problem with the OnNavigatedTo
method in the INavigationAware
interface.
When I show my view with RegionManager.RequestNavigate(myRegionName, myViewName)
,
OnNavigationTo
method is called.
But when I use RegionManager.RegisterViewWithRegion(myRegionName, typeof(myView))
RegionManager.RequestNavigate(myRegionName, myViewName2)
to my second view i am having a call to OnNavigatedFrom method of my first view.
My question is:
WhyOnNavigatedTo
method does not called and how i can get notic开发者_C百科e about view is shown when i use RegisterViewWithRegion
?Registering using the region manager will show the first view that was registered with it. It will never call OnNavigatedTo. Basically, to get it to do what you want to do, you'll need to "navigate" to your first View without OnNavigatedFrom to be called. To do this:
// Register all your views into the region
// The first View that is registered is automatically activated
regionManager.Regions["myRegionName"].Add(myView);
regionManager.Regions["myRegionName"].Add(myView2);
// Deactivate the View so it doesn't show in the UI
regionManager.Regions["myRegionName"].Deactivate(regionManager.Regions["myRegionName"].ActiveViews.First());
// Now navigate to your first screen
regionManager.RequestNavigate("myRegionName", "myView");
OnNavigatedTo should be called once, and OnNavigatedFrom should only be called after you request navigation to another View.
To allow view navigation you have to register it as an object, try something like that:
_container.RegisterType<Object, MainView>("MainView", new TransientLifetimeManager());
_regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<MainView>());
the first line allow you view navigation while the second will automaticly resolve the view as the region is created
精彩评论