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

ExpanderControl Inside ScrollViewer Control

3 Answers 158 Views
ExpanderControl
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aaron
Top achievements
Rank 1
Aaron asked on 12 Mar 2013, 09:49 AM
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.

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 12 Mar 2013, 02:42 PM
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.
0
Aaron
Top achievements
Rank 1
answered on 13 Mar 2013, 07:16 AM
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?
0
Accepted
Deyan
Telerik team
answered on 15 Mar 2013, 07:31 AM
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.
Tags
ExpanderControl
Asked by
Aaron
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or