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

PanelBar, multiple selection, and AutoScrollToSelectedItem

1 Answer 97 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Ema
Top achievements
Rank 1
Ema asked on 22 Jan 2014, 03:14 PM
Hi, 
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. 

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 24 Jan 2014, 11:42 AM
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()
        {
            InitializeComponent();
            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;                       
                    }
                }
 
                this.radPanelBar.ScrollViewer.ScrollToVerticalOffset(sumAllHeights);
            }
        }
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.

Regards,
Boris Penev
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
PanelBar
Asked by
Ema
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or