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

RadTabControl and MVVM Light

5 Answers 238 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Doots
Top achievements
Rank 1
Doots asked on 30 May 2012, 11:01 PM
Hi,

I'm using the RadTabControl in a WPF application using the MVVM Light Framework. My application has a main window with a RadTabControl, each tab has to display a different view/viewmodel. I would like to know if there is a best practice for loading these views into the RadTabControl ? Is there any code sample ?

Thanks for your help!
Doots

5 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tsvetkov
Telerik team
answered on 31 May 2012, 02:56 PM
Hello Ronald,

In such scenarios where you want to have different views for the different tabs you can take advantage of the ContentTemplateSelector property of the RadTabControl which allows you to apply different DataTemplates (Views) based on your custom logic in the ViewModels. Could you please examine the attached project which is a simple showcase of the described approach and tell me if it works for you?

Kind regards,
Viktor Tsvetkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Doots
Top achievements
Rank 1
answered on 31 May 2012, 11:04 PM

Hi Viktor,

I checked the solution you sent me and apparently it seems to fit with my needs but I am not really sure I got it perfectly. I need you to confirm some facts.

My application is built with:

  • A MainWindow (a view with it's own ViewModel) that contains a RadTabControl
  • I need to make each tab of the RadTabControl the host for a different View/ViewModel (each view is a UserControl who contains different controls)

Do you confirm that all i have to do is:

  • To add a "TabsList" property (ObservableCollection<ViewModelBase>) to my MainWindowViewModel ?
  • To create a DataTemplateSelector (and bind it to my RadTabControl) to pick the right template (a view) for each ViewModel in the TabsList ?
  • To bind the ItemsSource property of my RadTabControl to the TabsList of the MainWindowViewModel ?
  • To add a ViewModel instance to TabsList everytime i need to add a TabItem to my RadTabControl ?
  • To remove an instance of a ViewModel in TabsList everytime i want to remove a TabItem in my RadTabControl ?

Am I doing right or I misunderstood your answer and how to use the DataTemplateSelector with the RadTabControl and MVVMLight. Thanks a lot for your help :)

Ronald

0
Viktor Tsvetkov
Telerik team
answered on 01 Jun 2012, 08:17 AM
Hi Ronald,

Each point that you have mentioned is right so you have understood the given approach precisely. Still if you have some difficulties while implementing your idea do not hesitate to ask for further assistance.

All the best,
Viktor Tsvetkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Doots
Top achievements
Rank 1
answered on 03 Jun 2012, 05:14 PM
Thanks a lot Viktor, it works exactely as expected :)
0
Vuong Nguyen
Top achievements
Rank 1
answered on 26 Aug 2015, 04:25 AM

Hi Ronald,

 I am searching on this approach. Could you please help to share your solution to resolved about this.

Thank you so much.

 Vuong Nguyen

Tags
General Discussions
Asked by
Doots
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Doots
Top achievements
Rank 1
Vuong Nguyen
Top achievements
Rank 1
Share this question
or