Set Scroll Bar Position on Selected Page Change Event

3 posts, 0 answers
  1. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 22 Jul 2011 Link to this post

    Hi ,

    I am trying to do something very simple but seems that this does not work .

    Basically I have a few different RadPageViewPages in a  RadPageView control
    each page has about 9 buttons

    what I want to be able to do is when user clicks on a particular page this should auto scroll to make the contents of the page visible when expanded .i.e ideally scroll to a point where the contents become visible

    currently what seem to happen is when you click on the page to expand it depending on the position of the page the contents are not always visible the user has to manually drag the scrollbar to see its content which is obviously hiding down at the bottom .

    I tried adding the following code to the project but it does not seem to work

    void radPageView1_SelectedPageChanged(object sender, EventArgs e)
            {
                 
                RadPageView apageview = (RadPageView)sender;
                RadPageViewPage apage = (RadPageViewPage)apageview.SelectedPage;
     
                apageview.ScrollControlIntoView(apage);
            }

    I have added Screen-prints of what it does and what is expected

    Cheers
    Khizar

  2. Jack
    Admin
    Jack avatar
    2193 posts
    Member since:
    Sep 2012

    Posted 28 Jul 2011 Link to this post

    Hello Khizar,

    I apologize for the late reply. I was trying to find an acceptable solution for your question, because this seems to be a missing feature and I added it in our issue tracking system as a feature request. We will consider implementing it in a future version.

    My efforts, in fact, leaded to a solution, that I think covers your requirements. You can implement the desired behavior by overriding RadPageView class and doing some reflection. Please consider the following example:

    public class CustomPageView : RadPageView
    {
        public override string ThemeClassName
        {
            get { return typeof(RadPageView).FullName; }
            set {}
        }
     
        protected override RadPageViewElement CreateUI()
        {
            return new CustomExplorerBarElement();
        }
    }
     
    public class CustomExplorerBarElement : RadPageViewExplorerBarElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadPageViewExplorerBarElement);
            }
        }
     
        FieldInfo fi;
        MethodInfo mi;
     
        public CustomExplorerBarElement()
        {
            fi = typeof(RadPageViewExplorerBarElement).GetField("initialLayoutOffset", BindingFlags.Instance | BindingFlags.NonPublic);
            mi = typeof(RadPageViewExplorerBarElement).GetMethod("CorrectLayoutOffset", BindingFlags.Instance | BindingFlags.NonPublic);
        }
     
        public void ScrollTo(RadPageViewExplorerBarItem item)
        {
            RectangleF clientRect = this.GetClientRectangle(this.Size);
            Padding ncMargin = this.GetNCMetrics();
     
            clientRect.Y += ncMargin.Top;
            clientRect.X += ncMargin.Left;
            clientRect.Width -= ncMargin.Horizontal;
            clientRect.Height -= ncMargin.Vertical;
     
            RectangleF itemRectangle = item.BoundingRectangle;
            itemRectangle.Height += item.Page.Height;
            RectangleF intersectionRect = RectangleF.Intersect(clientRect, itemRectangle);
     
            fi.SetValue(this, (int)fi.GetValue(this) + (int)(clientRect.Top - itemRectangle.Top));
            int initialLayoutOffset = (int)mi.Invoke(this,new object[] {});
            fi.SetValue(this, initialLayoutOffset);           
            this.Scrollbar.Value = -initialLayoutOffset;
     
            this.InvalidateMeasure();
            this.UpdateLayout();
        }
     
        protected override void OnExpandedChanged(RadPageViewExpandedChangedEventArgs e)
        {
            base.OnExpandedChanged(e);
     
            if (e.Expanded)
            {
                UpdateLayout();
                Application.DoEvents();
     
                ScrollTo((RadPageViewExplorerBarItem)e.Item);
     
                InvalidateMeasure(true);
                UpdateLayout();
                Application.DoEvents();
            }
        }
    }

    I hope this solution fits in your case. If you have further questions, do not hesitate to ask.

    All the best,
    Jack
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Duncan Clarke
    Duncan Clarke avatar
    4 posts
    Member since:
    May 2009

    Posted 29 Aug 2011 Link to this post

    mistake

Back to Top