Oct 10, 2013 at 5:32 PM
Edited Oct 10, 2013 at 5:52 PM
When using a TabControl
you would need to Register each
on the TabRegion
in order to be the views available for Navigation. This way, the
would get instantiated on the
However, you can control the load and activation of every view with View Discovery
should not be used for registering Views
. Doing so, would make the Region
to navigate the requested
as you correctly mentioned.
Instead, you can register the views with the following alternatives:
// View discovery
// View injection
IRegion tabRegion = regionManager.Regions["TabRegion"];
var tabView1 = container.Resolve<FirstTabView>();
This way, only the FirstTabView
would become Active
when your application loads.
As I mentioned before, notice that View
instantiation would occur when registered to a
, so the View
gets available for navigation.
You can find more information on the following Prism Guide
If you don't want the Views
get instantiated because somehow they would take a long time to load, but also have tabs available to navigate to, you could think of a custom approach:
One possible way would be to register blank views in the TabRegion
, so you would be instantiating empty views at
. And then, define a Child Region
on each of these views where you would register your views by the time the corresponding tab is Navigated. You could
your views on a CollectionChanged
handler on each ViewModel when the active TabRegion View changes by subscribing to it as follows:
this.regionManager.Regions["TabRegion"].ActiveViews.CollectionChanged += ActiveViews_CollectionChanged;...
and verify is the corresponding view is already loaded:
void ActiveViews_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
foreach (var item in e.NewItems)
FrameworkElement tabview = item as FrameworkElement;
if (tabview != null && tabview.DataContext == this)
IRegion subRegion = this.regionManager.Regions[RegionNames.SubRegion];
if (subRegion == null) return;
// Check to see if we need to create an instance of the view.
FirstTabView firstTabview = subRegion.GetView("FirstTabView") as FirstTabView;
if (firstTabview == null)
// Create a new instance of the View using the container.
firstTabview = this.container.Resolve<FirstTabView>();
// Add the view to the subregion. This automatically activates the view too.
// The view has already been added to the region so just activate it.
I hope this helps,