ExpanderControl Inside ScrollViewer Control

4 posts, 1 answers
  1. Aaron
    Aaron avatar
    13 posts
    Member since:
    Dec 2012

    Posted 12 Mar 2013 Link to this post

    Hi Guys,

    I have multiple ExplanderControls inside a ScrollViewer control.  Everything is working fine until I get to the last ExpanderControl.  If I expand the last ExpanderControl, the ScrollViewer does not scroll down to show the details of the ExplanderControl.  How can I adjust the height of the ScrollViewer as the ExpanderControl is expanded and collapsed?

    Thanks for all your time.
  2. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 12 Mar 2013 Link to this post

    Hi Aaron,

    This is actually the out-of-the-box behavior of the ScrollViewer component. You can simply use the ScrollToVerticalOffset method to instruct the ScrollViewer to go to a given position.

    I hope this helps.

    Regards,
    Deyan
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Aaron
    Aaron avatar
    13 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2013 Link to this post

    Deyan,

    I know of that property but I am not sure what I should set that to!  When the last ExpanderControl is clicked on or expanded, what do I set the ScrollToVerticalOffset value to? Also what do I set the value of ScrollToVerticalOffset when the ExpanderControl is collapsed?  Do you have any sample code for this please?

    I have written the following which sort of works on the first time the ExpanderControl at the bottom of the ScrollViewer is expanded.  If you collapse the control and expand it a second time, it does not work.  Any ideas???

    private void ecExpanderControl_ExpandedStateChanged(object sender, ExpandedStateChangedEventArgs e)
    {
      if (e.IsExpanded == true)
      {
        GeneralTransform expanderTransform = ecExpanderControl.TransformToVisual(svScrollViewer);
        Rect rectangle = expanderTransform.TransformBounds(new Rect(new Point(ecExpanderControl.Margin.Left,
                                   ecExpanderControl.Margin.Top), ecExpanderControl.RenderSize));
        double newOffset = svScrollViewer.VerticalOffset + ((rectangle.Bottom + 100) - svScrollViewer.ViewportHeight);
        Dispatcher.BeginInvoke(() =>
        {
          svScrollViewer.ScrollToVerticalOffset(newOffset);
        });
      }
    }

    Thanks once again?
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 15 Mar 2013 Link to this post

    Hi Aaron,

    Since the RadExpanderControl opens with animation, simply catching the ExpandedStateChanged event would not be helpful enough. You may need to handle the LayoutUpdated event of the scrollviewer and constantly call the ScrollToVerticalOffset method by passing the maximum possible offset (depicted by the ScrollableHeight property of the ScrollViewer). This would pose further difficulties since the LayoutUpdated event is fired constantly when you're scrolling so you need to know when this event is fired because of scrolling operation, and when because of an expander being expanded. You can do this by observing the changes in the Visual States of the scrollviewer. There is an article on MSDN that describes how to do this:

    http://blogs.msdn.com/b/slmperf/archive/2011/06/30/windows-phone-mango-change-listbox-how-to-detect-compression-end-of-scroll-states.aspx

    This is what comes to my mind right now.

    Greetings,
    Deyan
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Back to Top
DevCraft banner