locked
Restoring horizontal scrollbar position for GridView bound to an incremental loading collection

    Question

  • Hi,

    in my app I have a list of items and when I click on an item I navigate to item detail page. The list is a GridView bound to an incremental loading collection.

    What I'd like to do is to restore GridView horizontal scrollbar position when I navigate back to the list of items.
    To do this I save GridView scrollviewer HorizontalOffset when I navigate from items list page and then when I navigate back I restore the position in tis way (when scrollviewer become visible):

    scrollViewer.ChangeView(_itemListPanelScrollViewerHorizontalOffset, null, null, true);

    This doesn't work when I scroll more pages in the list because when I navigate back, the list doesn't have all pages loaded previously since it's bound to an incremental loading collection and items are loaded only when I scroll the list.

    How can I solve the problem?


    Wednesday, April 30, 2014 4:24 AM

All replies

  • I'm trying to figure out if what you want is to restore the actual scrollbar position, or bring an item back into view, which would make more sense. There's a ScrollIntoView method on GridView:

    http://msdn.microsoft.com/en-us/library/windows/apps/br242911.aspx

    I think this is what you're really after.  If it's not, please say so.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 30, 2014 12:38 PM
    Moderator
  • Hi,

    I think ScrollIntoView works only if the item is visible in the list but in my case the item may not be in the list, especially when the item is in a page that is not loaded yet.

    Incremental loading collection are great but I can't figure out how can I restore the scrollbar position.
    Maybe I have to call ChangeView several times until I reach the final offset.

    Wednesday, April 30, 2014 1:24 PM