View With TabControl that contain mulitple Views

Topics: Prism v4 - WPF 4
Sep 20, 2012 at 8:57 PM
Edited Sep 20, 2012 at 10:53 PM

Hello all,

Here is the scenario I am running into, and it does not make much sense. 

I have a view which contains a tab control, each tab contain multiple views and their own view models. 

When the tab control loads, and I try to switch between tabs, it takes a long time on the first click to switch views.  Subsequent clicks are fine and run very well.

I have my region defined as contentControl and not TabControl, as NOT all views will have tabs on them, or use the tab control at all. 

Is there anything I can do to make this first click faster?

Any feedback you provide is greatly appreciated.

Sep 21, 2012 at 8:38 PM


Based on your description, it seems that the problem is the creation / initialization of the views and view models, as you are only experiencing a delay the first time the views are shown. In my opinion, the first thing to check would be the view and view models involved to see if their are using any heavy resources or if there is any code that could be temporally blocking their construction / initialization (for example, retrieving data from a service).

If you believe that your view / view models are not the cause of this undesired behavior, another test you could make is replacing (for testing purposes) in another kind of region (for example, an ItemsControl) to check if this delays also appears after changing the UI Element hosting those views.

Finally, if when switching views you are loading modules on demand, this behavior could be produced by the overhead required to load and initialize each module, specially if those modules require to load big sized assemblies.

Also, I believe you might find useful tips in the following MSDN article:

I hope this helps you find the cause behind this,

Damian Cherubini

Sep 22, 2012 at 11:26 PM
Edited Sep 22, 2012 at 11:29 PM

I understand your point fully, but let me explain little further.  I have a view with a tab control: 

<TabControl x:Name="mainOrderTabControl"
			<TabItem Header="Details">
				<localViews:DetailsView />
			<TabItem Header="Order Lines">
				<localViews:OrderLinesView />
			<TabItem Header="Status">
				<localViews:StatusView />
			<TabItem Header="Notes">
				<localViews:NotesView />
Let's look at the OrderLinesView which consists of the following xaml:  
<Grid Grid.Column="0"
			<localViews:LinesView />
		<Grid Grid.Column="1"
			<localViews:CreativeServicesView  />
		<Grid Grid.Column="1"
			<localViews:LocationsView />
Correct me if I am wrong here or I have mis-understanding,  when I click on the second tab which is the orderlinesviews, 
I am expecting all views below it to get "automagically" initialized and their view models, I put a break point on every 
constructor for OrdersDetailsView, LinesView, CreativeServicesView, and LocationsView and none of the constructors are created.
But if in the MainOrder View model, which hosts the tabcontrol above, I place the following line of code: 
_unityContainer.Resolve<OrderLinesView>(new ParameterOverride("orderLines", new ObservableCollection<OrderLine>()).OnType<OrderLinesViewModel>());
Then it seems the constructor for the ordersDetailsView get called but not the other views which I would want them to do that? 
am I doing something wrong? what is the right way of doing it?
Sep 25, 2012 at 5:45 PM

Anything that can help me please?  Anyone.

Sep 26, 2012 at 6:21 AM

Can you post the code behind of OrderLinesView and its viewmodel? Need to see what's happening there?