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
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 >>
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
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 >>
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