PanelBar, multiple selection, and AutoScrollToSelectedItem

2 posts, 0 answers
  1. Ema
    Ema avatar
    3 posts
    Member since:
    Nov 2013

    Posted 22 Jan 2014 Link to this post

    I have a PanelBar with the flag ExpandMode="Multiple".
    When the sum of the heights of the expanded PanelBarItems is greater than the height of the container, a vertical scrollbar appears. But if the PanelBarItem expanded is the last in the item list, I would like that the PanelBarItem elements automatically appear like the figure2, so that the scrollbar automatically scrolls to the selected item, and not like figure1.

    I used AutoScrollToSelectedItem="true", but it doesn't work. 

  2. Boris
    Boris avatar
    276 posts

    Posted 24 Jan 2014 Link to this post

    Hello Ema,

    The AutoScrollToSelectedItem property is a member of RadPanelBar Class which is inherited from RadTreeView, but actually it is implemented only for RadTreeView and not for the RadPanelBar. In order to achieve a similar behavior in PanelBar you can use RadPanelBar's Expanded event like so:
    public partial class MainPage : UserControl
            private double sumAllHeights = 0.0;
            private RadPanelBarItem lastExpanded;
            public MainPage()
                this.radPanelBar.ItemsSource = MyViewModel.GenerateItems();
            private void radPanelBar_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e)
                var container = e.OriginalSource as RadPanelBarItem;
                this.lastExpanded = container;
                this.sumAllHeights = 0.0;
                if (this.radPanelBar!= null && container != null)
                    for (int i = 0; i < container.Index; i++)
                        var currContainer = this.radPanelBar.ItemContainerGenerator.ContainerFromIndex(i) as RadPanelBarItem;
                        if (currContainer != null)
                            sumAllHeights += currContainer.ActualHeight;                       
    In this snippet we calculate the sum of the ActualHeights of all RadPanelBarItems which are before the expanded one and then we invoke the ScrollToVerticalOffset method of the PanelBar's ScrollViewer with parameter this sum.

    We think this code is a good starting point for your scenario and we also believe that you can handle the border cases by calculating the exact scroll offset.

    Please feel free to let us know if this helps you.

    Boris Penev
    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 >>
Back to Top