Dynamic TabControl / TabItem - How to wire up View/ViewModel

Topics: Prism v4 - WPF 4
Apr 13, 2011 at 6:36 PM

Basically I'm stuck in the following scenario:

Shell.xaml, UserControl1.xaml, UserControl2.xaml, UserControl3.xaml (each has their own ViewModel which is extended from NotificationObject).

 

My ShellViewModel needs to be able to manage the TabControl and load in not only TabItems, but also the content that goes inside the TabItem as one of the UserControls, which need to be wired up to their corresponding ViewModels. I'm running into some issues and I'm not sure how to wire this up appropriately following MVVM.

I'm using MEF, so I figure that should help me import/export. I'm not sure if this helps or not. Any advice as to how to accomplish this would be great.

 

One big decision is my ObservableCollection I have bound to the TabControl, should it be a collection of ViewModels or TabItems?

Developer
Apr 13, 2011 at 7:34 PM

Hi,

Your TabControl could be a Region, and then you could add your items as views of that region. You could add the ViewModels, for example using Region Navigation, and define the view as the DataTemplate for that ViewModel, or you could add the View and wire up the ViewModel to the View by using for example the Import attribute and assigning the ViewModel as the View's DataContext.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Sep 1, 2012 at 2:25 PM

Hi, 

 

Can you please show an example? this is exactly my problem too. I'm fairly new and am quite desperate to know how to achieve this

http://compositewpf.codeplex.com/discussions/394045