Setting IsSelected across RadTabItem's

2 posts, 0 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 03 Jul 2013 Link to this post

    I have the following View code:

                    <telerik:RadTabControl IsContentPreserved="True" ItemsSource="{Binding}" >
                        <telerik:RadTabItem Header="Tab1" Height="30" IsSelected="{Binding ShowTab1, Mode=OneWay}"></telerik:RadTabItem>
                        <telerik:RadTabItem Header="Tab2" Height="30"></telerik:RadTabItem>
                        <telerik:RadTabItem Header="Tab3" Height="30" ></telerik:RadTabItem>
                        <telerik:RadTabItem Header="Tab4" Height="30" ></telerik:RadTabItem>
                        <telerik:RadTabItem Header="Tab5" Height="30" IsSelected="{Binding ShowTab5, Mode=OneWay}"></telerik:RadTabItem>
    with the these properties in my ViewModel:
    public virtual bool ShowTab5
                return _showTab5;
                _showTab5 = value;
                ShowTab1 = !value;
    public virtual bool ShowTab1
                return _showTab1;
                _showTab1 = value;

    ShowTab5 gets set the first time thru, but afterwards I set ShowTab5 to false and Tab1 doesnt 'come to the front', like Tab5 did initially.  Any ideas?
  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 08 Jul 2013 Link to this post

    Hello J,

    The RadTabControl allows only one tab to be selected at a time. Which means that as soon as you trigger a change in the selection  through modifications in the ViewModel, the RadTabControl triggers its selection changing logic trying to change the selection. And in order to allow the control to swiftly change the IsSelected values of both tabs, I'd recommend using a TwoWay binding.

    Also, I noticed that you've set the Items and ItemsSource collections of the control. However, please note that you can't set both properties simultaneously. Instead, you need to decide whether you'll use the Items collection by defining RadTabItems in xaml or code behind or you need to populate the RadTabControl from a collection with business items. The ItemsSource property allows you to use a business collection to dynamically generate RadTabItems that wrap the business data as demonstrated in this tutorial.

    In your case you can remove the ItemsSource property altogether. Please give this a try and also use a TwoWay binding for the IsSelected properties and let me know if you still experience issues with your implementation.

    Tina Stancheva
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft R3 2016 release webinar banner
Back to Top