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

Having first tab selected after binding

4 Answers 275 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Frédéric
Top achievements
Rank 1
Frédéric asked on 20 Apr 2011, 07:44 PM
Hi,

I have a tab control that has is ItemSource binded to a collection as shown here : http://www.telerik.com/help/silverlight/radtabcontrol-populating-binding-to-collection.html

However, after the tabs are populated from the collection, there is no tab selected.

I would like that after every rebind of the ItemSource, the first tab be always selected.

I tried the property IsDefaultItemSelected="True" of the TabControl with no luck.

Thanks

Frederic

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 26 Apr 2011, 09:07 AM
Hello Frédéric,

 
The IsDefaultItemSelected property indicates whether the first tab item will be selected only at start up. It won't work when the Items Source is re-bound which is expected. When re-binding, you can bind the SelectedItem, SelectedIndex of the RadTabControl or the IsSelected property of the RadTabItem. Let us know if you need more info.

Kind regards,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brian
Top achievements
Rank 1
answered on 18 May 2011, 10:42 PM
I have a sample project that is shows of an issue I'm having in my project.  I have the ItemsSource and SelectedItem of a TabControl bound to my view model but the SelectedItem is not getting set.  In my project, the initial load works OK but not when the ItemsSource is re-bound, the SelectedItem is never shown, just like in in my example.

Can you explain why the SelectedItem does not get set?
Tks.

Here is the code:
ViewModel
public class MainPageViewModel : INotifyPropertyChanged
    {
        public MainPageViewModel()
        {
            this.ReloadDataCommand = new DelegateCommand(
                delegate
                {
                    this.LoadData();
                },
                delegate
                {
                    return true;
                });
  
            LoadData();
        }
  
        public void LoadData()
        {
            PersonList = new List<Person>();
            PersonList.Add(new Person { FirstName = "Bob", LastName="Smith", Phone="222-222-2222"});
            PersonList.Add(new Person { FirstName = "Steve", LastName = "Larson", Phone = "444-444-4444" });
            PersonList.Add(new Person { FirstName = "Mark", LastName = "Black", Phone = "555-555-55555" });
            PersonList.Add(new Person { FirstName = "Sandy", LastName = "Nelson", Phone = "777-777-7777" });
            PersonList.Add(new Person { FirstName = "Paul", LastName = "Anderson", Phone = "888-888-88888" });            
  
            NotifyPropertyChanged("PersonList");
  
            SelectedPerson = PersonList[0];
            NotifyPropertyChanged("SelectedPerson");
        }
  
        public List<Person> PersonList { get; set; }
        public Person SelectedPerson { get; set; }
  
        #region Commands
  
        public DelegateCommand ReloadDataCommand { get; set; }
  
        #endregion
  
        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
  
        public void NotifyPropertyChanged(string propertyName)
        {
            var handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
  
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Phone { get; set; }
  
    }

View:
<UserControl x:Class="TabControlTest.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="368" d:DesignWidth="927">
  
    <UserControl.Resources>
  
        <DataTemplate x:Key="RadTabHeaderTemplate">
            <TextBlock Text="{Binding LastName}" Margin="10,2,10,0" MinWidth="80" />
        </DataTemplate>
  
        <DataTemplate x:Key="ContentTemplate">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <TextBlock Text="{Binding FirstName}" />
                <TextBlock Text="{Binding LastName}" Margin="20,0,0,0" />
                <TextBlock Text="{Binding Phone}" Margin="20,0,0,0" />
            </StackPanel>
        </DataTemplate>
  
    </UserControl.Resources>
      
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Vertical">
          
            <telerik:RadTabControl SelectedItem="{Binding SelectedPerson, Mode=TwoWay}"
                                    ItemsSource="{Binding PersonList}"
                                    ItemTemplate="{StaticResource RadTabHeaderTemplate}"
                                    ContentTemplate="{StaticResource ContentTemplate}"
                                    DropDownDisplayMode="Collapsed" ScrollMode="Viewport"
                                    Height="Auto" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                    Padding="10" telerik:StyleManager.Theme="Windows7"
                <telerik:RadTabItem>
                      
                      
                </telerik:RadTabItem>
            </telerik:RadTabControl>
              
            <Button Content="Reload Data" Command="{Binding ReloadDataCommand}" Width="100" />
        </StackPanel>
  
    </Grid>
</UserControl>
0
Petar Mladenov
Telerik team
answered on 24 May 2011, 09:46 AM
Hello Brian,

I managed to reproduce your issue with the official Q1 2011 dlls (0315). The good news is that we have re-factored our selection logic recently and this appears to be fixed with the Q1 2011 SP1 version ( 0419). You can examine it in the attached solution. Let us know if you need further assistance.

All the best,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brian
Top achievements
Rank 1
answered on 26 May 2011, 07:25 PM
At first test, this appears to be fixed with the latest version as you said. 

Thanks for getting this fixed!
Tags
TabControl
Asked by
Frédéric
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Brian
Top achievements
Rank 1
Share this question
or