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

Setting IsSelected across RadTabItem's

1 Answer 208 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 03 Jul 2013, 08:27 PM

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>
                </telerik:RadTabControl>
with the these properties in my ViewModel:
public virtual bool ShowTab5
      {
         get
         {
            return _showTab5;
         }
         set 
         {
            _showTab5 = value;
  
            ShowTab1 = !value;
  
            OnPropertyChanged("ShowTab5");
         }
      }
  
public virtual bool ShowTab1
      {
         get
         {
            return _showTab1;
         }
         set 
         {
            _showTab1 = value;
            OnPropertyChanged("ShowTab1");
         }
      }

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?

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 08 Jul 2013, 01:06 PM
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.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
Tags
TabControl
Asked by
J
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or