Tab control and RadComboBox ItemsSource Binding

3 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 24 May 2011 Link to this post

    I think I found a bug when I try to repopulate a RadTabControl and I have a radcombobox whose ItemsSource is binding.
    First off I set
    myTabControl.DataContext = myBigClassOfStuff;  //This class has many objects including a list for the ItemsSource of the radcombobox

    Say I click a button and when I get my new result of myBigClassOfStuff, I again call:
    myTabControl.DataContext = myBigClassOfStuff;

    For all textboxes and radcomboboxes that don't have their ItemsSource binding (but ItemsSource set programatically in the code), everything is fine.  The radComboxes that do have their itemsource filled, but the selected item isn't selected.  Also the value of
    myBigClassOfStuff.selectedValue will become null if myTabControl.DataContext already has a value.
    If I do this:
    myTabControl.DataContext = null;
    myTabControl.DataContext = myBigClassOfStuff;

    Then everything is almost ok and myBigClassOfStuff.selectedValue will keep it's original value.  This would be fine, but there is one more strange thing the tab control does.   When I do that and I'm on a different tab than the radcombobox I'm interested in, the selected value won't show up when I go to that tab.  When I'm on that tab and get my new myBigClassOfStuff everything is fine though.
    When I programatically populate the dropdown boxes everything is ok.  Maybe I'll just do that.  Any suggestions, or things I'm doing wrong?

    myBigClassOfStuff.AllContacts  - is a list of a class
    myBigClassOfStuff.AttentionId  - is the selected value of the RadComboBox
    <telerik:RadComboBox ItemsSource="{Binding AllContacts}"  SelectedValue="{Binding AttentionId}" ...

  2. Answer
    Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 27 May 2011 Link to this post

    Hi danparker276,

    I couldn't reproduce your issue on our side but I am not really sure if I understand your scenario correctly.

    Basically when I bind the RadComboBox.SelectedItem and the RadTabControl.SelectedItem properties with TwoWay binding and I implement INotifyPropertyChanged in my business class, the control works as expected.

    However, by default the RadTabControl creates only one ContentPresenter for the currently selected TabItem and uses it to display the content of this TabItem. Then when you select another RadTabItem, its content is rendered in the same ContentPresenter and therefore the content of the previously selected item is removed from the visual tree thus not holding its state.

    If you want to change that behavior and keep each RadTabItem's Content you can set the RadTabControl.IsContentPreserved property to True. That might help you get over your issues.

    Still, I attached the sample project I created to test your scenario so that you can have a look at it and let me know if it works for you or if I am missing something.

    Tina Stancheva
    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
  3. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 27 May 2011 Link to this post

    Thanks "RadTabControl.IsContentPreserved property to True " did the trick.

Back to Top