RadTabControl and MVVM Light

6 posts, 1 answers
  1. Doots
    Doots avatar
    13 posts
    Member since:
    Apr 2011

    Posted 30 May 2012 Link to this post

    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
  2. Answer
    Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 31 May 2012 Link to this post

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Doots
    Doots avatar
    13 posts
    Member since:
    Apr 2011

    Posted 31 May 2012 Link to this post

    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

  5. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 01 Jun 2012 Link to this post

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

  6. Doots
    Doots avatar
    13 posts
    Member since:
    Apr 2011

    Posted 03 Jun 2012 Link to this post

    Thanks a lot Viktor, it works exactely as expected :)
  7. Vuong Nguyen
    Vuong Nguyen avatar
    1 posts
    Member since:
    Jul 2015

    Posted 25 Aug 2015 in reply to Doots Link to this post

    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

Back to Top
UI for WPF is Visual Studio 2017 Ready