Is there a way to stop RadPanelBar from resetting when rebinding to datasource?

2 posts, 1 answers
  1. Ryan
    Ryan avatar
    33 posts
    Member since:
    May 2009

    Posted 03 Nov 2009 Link to this post

    When the ItemsSource property is set by a background task (periodic timer), the RadPanelBar resets, i.e. the panels collapse and the selected item highlight disappears.

    I have implemented a cache to save the state of the RadPanelBar and RadPanelBarItems so that it can be restored to its original state, after the ItemsSource property has been set. However this is causing a horrible flicker.

    Is there a way to maintain the state of the RadPanelBar after the ItemsSource property has been set without having to do manually?

    Would binding to an ObservableCollection instead make any difference?
    (admittedly perhaps I should have done this in the first place, but didn't know about it until recently).

  2. Answer
    Tihomir Petkov
    Tihomir Petkov avatar
    576 posts

    Posted 04 Nov 2009 Link to this post

    Hello Ryan,

    What you observed while changing the ItemsSource property is the expected behavior. In fact, all ItemsControls behave in the same way. When you set (or reset) the ItemsSource property, what happens behind the scenes is that RadPanelBarItem objects are created on the fly and used to wrap your business objects. So, when you change the ItemsSource, the visual elements are destroyed and new ones a created for your new data source.

    In case you need to update only certain items in your source and/or you want to avoid the re-generation of the visual items you should use an ObservableCollection for your data source. If you have a hierarchy of objects, you will need to make their items collections ObservableCollections as well. This way any changes in your source collection will be reflected in the layout of your application without rebuilding the entire tree of visual elements that comprise your PanelBar.

    I hope I was able to help. Please let me know if you have any other questions.

    Tihomir Petkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top