4

In my WP8 app I'm trying to implement a functionality that will allow me to save LongMultiListSelector's scroll position and scroll it to that position at a later time (after tombstoning for example). It proved to be quite a quest and despite some progress I still have questions.

As I understand it now I'll need the following things for this to work:

  1. Obviously an ability to scroll to a specified item which I now have. (LongMultiListSelector, despite being an extension of LongListSelector, does not have ScrollTo method, although LongListSelector can be found in LongMultiListSelector's visual tree and that is what I've done).

    1.1. Ability To scroll to a specified item with animation and this one I haven't solved yet. It is not that important but having it would be nice. After some searching I've found out that once LongListSelector had AnimateTo method but currently it has it not.

  2. Ability to find out what items of LongListSelector are currently visible on screen so I can save index of one of these visible items and then scroll to it. This one I also have not solved yet and it is very important.

    After some searching I've found this question: WP7 Toolkit Update Removed GetItemsInView() from the LongListSelector. Is says that in former times LongListSelector had a GetItemsInView function, at a later times it had Link and Unlink events especially for this purpose. Currently LongListSelector has neither of these options.

    So the main question is what should I do now to find visible items in LongListSelector?

Community
  • 1
  • 1
src091
  • 2,807
  • 7
  • 44
  • 74

2 Answers2

4

I looks like currently there's no easy and direct way at all to find which items are visible. Fortunately not everything is lost. Both ScrollBar and LongListSelector can be found in LongListSelector's visual tree at runtime.

LongListSelector is needed for it's ScrollTo method and from ScrollBar I need a ValueChanged event where I can get ScrollBar.Maximum and ScrollBar.Value which are control height and current offset, respectively. The problem again is that these two properties are not always calculated correctly perhaps due to LongListSelector's virtualization and the fact that it does not show all the items at once. Good thing is that negative distance (Maximum - Value, an offset from end of list) is, although relative, always right.

So if it's possible for you to manually calculate real height of your LongListMultiSelector then scroll management becomes possible using that real height and negative distance. In my case it was easy because all of the items are of the same height.

src091
  • 2,807
  • 7
  • 44
  • 74
  • Anton do you have any code example of this online? A github gist or something? I'm interested in this manual calculation approach! – Depechie Feb 12 '14 at 12:25
0

Answer to Ability To scroll to a specified item with animation:

This article will help you.

The main idea: ScrollViewer's VerticalOffset Property is marked as read-only. So you can create a shell-class that will help you to animate VerticalOffset.

Chepene
  • 1,128
  • 1
  • 12
  • 18