locked
ScrollViewer and ScrollToHorizontalOffset problem RRS feed

  • Question

  • I have a StackPanel inside a ScrollViewer.  I am trying to set a scroll position to an item in the stack.  I am doing this code on the NavigateToEvent.  This works fine when the page loads, yet it seems to have uncovered a problem with the ScrollViewer.  If I do not set the ScrollToHorizontalOffset, all if fine.  However, if I set the ScrollToHorizontalOffset, the ScrollViewer will not longer scroll horizontally anymore.


    FierceMuppet

    Monday, January 14, 2013 6:56 PM

All replies

  • Hi,

    How did you set the scroll position to an item in the stack? Could you please show me some code?


    Aaron
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 16, 2013 8:23 AM
  • I have fixed width controls in the scrollviewer, so I am setting the offset based on what is there.

    ScrollContainer.ScrollToHorizontalOffset(width);

    Note that I am setting this value in the LayoutUpdated event.


    FierceMuppet


    Thursday, January 24, 2013 4:29 PM
  • I found that you have to make sure to use ".ActualWidth" vs. "Width" with offsets (actual width is the currently rendered width).  Also, putting .UpdateLayout() also helps.  So:

    ScrollContainer.UpdateLayout();

    ScrollContainer.ScrollToHorizontalOffset(stackpanel1.ActualWidth - [how far to the left]);



    • Proposed as answer by NelsonCarrillo Friday, January 25, 2013 12:10 AM
    Thursday, January 24, 2013 5:06 PM