Enabling tabitem and switching between tabs through view model

2 posts, 0 answers
  1. Santhosh
    Santhosh avatar
    3 posts
    Member since:
    Nov 2011

    Posted 14 Nov 2011 Link to this post

    Hi,

    I am having problem in enabling tabitems and switching between tabs through view model when using RadTabControl in silverlight 4.0.

    I am having the following views and viewmodels
     BaseViewmodel- Tabcontrol
    Tab1Viewmodel-Tabitem1(usercontrol1)
    Tab2Viewmodel-tabitem2(usercontrol2)

    In my base view model, i am having the following property

    private int m_currentstep
     public int CurrentStep
            {
                get
                {
                    return m_CurrentStep;
                }
                set
                {
                    m_CurrentStep = value;
                    NotifyPropertyChanged(m => m.CurrentStep);
                }
            }
     and i am binding this to selectedindex property of tabcontrol.



    When i loaded this tabcontrol, tabitem1 should be displayed and tabitem2 should be disabled. Only when i click submit button in tabitem1, tabitem2 should be enabled and focus should be switched to tabitem2.

    Both the tabviewmodels are derived from baseviewmodel. In button click event of tabitem1, i set currentstep=1(for tabitem2), but focus is not moved.. Also i have 2 more properties tabitem1enabled and tabitem2 enabled and i am binding this to Isenabled property of tabitems and set the value for tabitem2 =true in the same button click event. But tabitem2 is not enabled. Please let me know how this should be done using Rabtabcontrol?
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Nov 2011 Link to this post

    Hi Santhosh,

    I am not entirely sure how you implement the described scenario, but the information you gave us, indicates that the RadTabItems and the RadTabControl all use different instances of the BaseViewmodel as DataContext. This is why when you try to control the BaseViewmodel.CurrentStep from the RadTabItems ViewModels, you're actually changing another instance of the BaseViewmodel, not the instance that the RadTabCantrol is bound to.

    This is why I'd recommend using entirely an MVVM approach. You can bind the RadTabControl ItemsSource collection to a collection of business items. Use the RadTabControl.ContentTemplate property to define the content of each RadTabItem and create a command to change the SelectedIndex. I attached a sample project demonstrating this approach.

    Also, if you need to display different content for the items, then you can create a DataTemplateSelector and use it as a ContentTemplateSelector.

    Please give this approach a try and let us know how it goes.

    Regards,
    Tina Stancheva
    the Telerik team

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

  3. DevCraft banner
Back to Top