How to ScrollToTop

7 posts, 0 answers
  1. Karl Mikesell
    Karl Mikesell avatar
    55 posts
    Member since:
    May 2010

    Posted 06 Jul 2010 Link to this post

    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?

  2. Karl Mikesell
    Karl Mikesell avatar
    55 posts
    Member since:
    May 2010

    Posted 06 Jul 2010 Link to this post

    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?
  3. DevCraft banner
  4. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 09 Jul 2010 Link to this post

    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
  5. Karl Mikesell
    Karl Mikesell avatar
    55 posts
    Member since:
    May 2010

    Posted 15 Jul 2010 Link to this post


    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
  6. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 19 Jul 2010 Link to this post

    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
  7. Karl Mikesell
    Karl Mikesell avatar
    55 posts
    Member since:
    May 2010

    Posted 20 Jul 2010 Link to this post

    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?
  8. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 22 Jul 2010 Link to this post

    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
Back to Top
DevCraft banner