This is a migrated thread and some comments may be shown as answers.

MVVM - UI Tabbed with each Tab has a different View/ViewModel

3 Answers 186 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Guillaume
Top achievements
Rank 1
Guillaume asked on 21 Feb 2011, 10:45 AM
Hello,


In my project, i have to create an administration interface with a menu. At each clic on this menu, a new tab will open.
Because, i am in MVVM, each tab is a ViewModel different (which inherit from the same ViewModel base class) and a View different.

I have define an ItemTemplate for override the header but it's common for all tabs instead of the content is not.
My TabControl is binded to an ObservableCollection of ViewModel base class.


I had open your C# example but in it, all tabs have the same content template.


So, how can i load the right view in interface according to its ViewModel ?

I use MVVM-Light and many thinks for your help !


Regards,
Guillaume

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 21 Feb 2011, 01:45 PM
Hello Guillaume,


Please excuse me for the unfinished example. Here you can find the modified sample showing the usual use of DataTemplateSelectors. Check it out and let me know how it goes. Thank you for your cooperation.

Kind regards,
Petar Mladenov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Guillaume
Top achievements
Rank 1
answered on 22 Feb 2011, 10:23 AM
Hello Petar,

Thanks for your help.
I saw your example and try to do same thing but it doesn't work.

My RabTabControl is like that :
<telerik:RadTabControl Grid.Row="2"
                               Margin="0,10,0,0"
                               BackgroundVisibility="Collapsed"
                               ItemsSource="{Binding ViewModelsTab}"
                               SelectedIndex="{Binding SelectedTabIndex}"
                               ItemTemplate="{StaticResource TabHeaderTemplate}"
                               ContentTemplateSelector="{StaticResource ViewTemplateSelector}"/>

The ItemsSource is binded to : 
public ObservableCollection<TabViewModelBase> ViewModelTabItems

which is in my ViewModel.

I have created a class that extends your DataTemplateSelector and overrides the Select method. It is in my App.xaml like that :
<res:ViewSelector x:Key="ViewTemplateSelector" />

For testing, in my ViewModel of MainPage (which contains my ObservableCollection), i add a TabViewModelBase to my collection, so i should pass in Select method of ViewSelector but, in debug, my breapoint is never fired.

Where i'm wrong ?


Regards,
Guillaume
0
Guillaume
Top achievements
Rank 1
answered on 22 Feb 2011, 04:18 PM
Shame on me !

In xaml, on ItemsSource property, i have put the old name of ObservableCollection.

Tags
TabControl
Asked by
Guillaume
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Guillaume
Top achievements
Rank 1
Share this question
or