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

How to ScrollToTop

6 Answers 71 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Karl Mikesell
Top achievements
Rank 1
Karl Mikesell asked on 06 Jul 2010, 09:16 PM
Using the PanelBar by adding items dynamically; however, the PanelBar has scroll bar always appearing at the bottom (last item added) of section; note Horizontal orientation.  How can the scroll bar be made to Scroll to top of selected header?  

<telerikNavigation:RadPanelBar Grid.Row="1" x:Name="Views" BorderBrush="Transparent" Orientation="Horizontal" IsTabStop="True" ExpandMode="Single" MaxHeight="595" MaxWidth="640">
<telerikNavigation:RadPanelBar.Background><ImageBrush/>/telerikNavigation:RadPanelBar.Background>
</telerikNavigation:RadPanelBar>

 

 

Ideas?

6 Answers, 1 is accepted

Sort by
0
Karl Mikesell
Top achievements
Rank 1
answered on 06 Jul 2010, 10:52 PM
Add an Expanded Event
private void RadPanelBarItem_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
ScrollViewer sv = Views.ScrollViewer;
 RadPanelBarItem rbItem = (RadPanelBarItem)sender;if (rbItem.Level == 1)
 {
 RadPanelBarItem rbItemChild = (RadPanelBarItem)rbItem.Items[0];
 rbItemChild.IsSelected = true;
 Views.UpdateLayout();
 sv.ScrollIntoView(rbItemChild);  } 
}

This does not work always, also does an Event exist to know when the ScrollViewer value is changed, the issue here is when scrolling the Header scrolls out of view, would like to move header (i.e. Text Block) in relation with vertical scrolling.

Ideas?
0
Kiril Stanoev
Telerik team
answered on 09 Jul 2010, 02:27 PM
Hello Karl,

I am not sure where the ScrollIntoView is coming from, since ScrollViewer has no such method as ScrollIntoView.I've prepared a small example that shows one possible way to bring the expanded item into view.
To find either the vertical or horizontal scrollbars in the PanelBar's ScrollViewer, you can do the following:

ScrollBar scrollBar;
public MainPage()
{
    InitializeComponent();
 
    Loaded += new RoutedEventHandler(MainPage_Loaded);
}
 
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
    {
        var root = VisualTreeHelper.GetChild(this.Views.ScrollViewer, 0) as Border;
        scrollBar = root.FindName("VerticalScrollBar") as ScrollBar;
        MessageBox.Show(scrollBar != null ? "ScrollBar found" : "ScrollBar not found");
    });
}


Kind regards,
Kiril Stanoev
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
Karl Mikesell
Top achievements
Rank 1
answered on 15 Jul 2010, 08:54 PM

The RadPanelBar contains ScrollViewer which contains the method ScrollIntoView(FrameworkElement)

The problem using the RadPanelBar is tabbing through or using the keyboard down arrow key moves to the next RadPanelBarItem (GotFocus event fires), but the veritical scroll will not follow.

Using the ScollIntoView method seems to only work with the Level = 1 RadPanelBarItems, when tabbing through the level = 2 items the ScollIntoView does not work.

How can the RadPanelBar be used without a mouse?  When to scroll bar never moves?

Using version 2010.2.609.1040

Hope there is a workaround
0
Kiril Stanoev
Telerik team
answered on 19 Jul 2010, 01:45 PM
Hi Karl,

Unfortunately with the current implementation, the Keyboard navigation does not behave as expected and there is no workaround I can offer you regarding this scenario. We will be working on fixing those issues in RadPanelBar and you can expect significant improvement in the behavior with our Q2 Service Pack 1 release, which is scheduled for the middle of August this year.

Greetings,
Kiril Stanoev
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
Karl Mikesell
Top achievements
Rank 1
answered on 20 Jul 2010, 05:48 PM
When selecting (programatically) RadPanelBarItem can the ScrollViewer be made to move?  This is only working for Level 1 Items, Level 2 are selected but scroll will not move?
0
Kiril Stanoev
Telerik team
answered on 22 Jul 2010, 04:02 PM
Hi Karl,

If you modify the Expanded event handler and multiply not by expandedItem.ActualHeight but by 22 (which is the default Height of all the Level 1 panel bar items) should be enough:

private void RadPanelBarItem_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadPanelBarItem expandedItem = sender as RadPanelBarItem;
 
    RadPanelBarItem rootItem = null;
 
    if (expandedItem.Level == 1)
    {
        rootItem = expandedItem;
    }
    else
    {
        rootItem = this.GetRootPanelBarItem(expandedItem);
    }
 
    int index = this.Views.Items.IndexOf(rootItem);
    double totalHeight = index * 22; // 22 is the default height of the PanelBarItem
    this.Views.ScrollViewer.ScrollToVerticalOffset(0);
    Dispatcher.BeginInvoke(() =>
    {
        this.Views.ScrollViewer.ScrollToVerticalOffset(totalHeight);
    });
 
}
 
private RadPanelBarItem GetRootPanelBarItem(RadPanelBarItem pbi)
{
    if(pbi.ParentItem != null)
    {
        return this.GetRootPanelBarItem(pbi.ParentItem);
    }
    else
    {
        return pbi;
    }
}

Of course multiplying by such magic numbers is not a good practice  but this is the most straightforward way. Let me know if you have further questions or comments regarding this topic.

Kind regards,
Kiril Stanoev
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
Tags
PanelBar
Asked by
Karl Mikesell
Top achievements
Rank 1
Answers by
Karl Mikesell
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or