1

In my WP8 application I use LongListMultiSelector and I would like to save it's scroll position when application is closed or tombstoned and then restore it when application is opened again. I will also need to scroll it programmatically to a specified item or specified position with animation when application is active.

The problem is that so far I can't find any methods on LongListMultiSelector that will allow me to scroll it with or without animation to a specified item or position. I also can't find methods that will allow me to get a list of all current items so I could choose of them to which one to scroll.

It can't be that scrolling is unmanageable on LongListMultiSelector so I'd like to get your advice on how I can get to this scroll functionality.

src091
  • 2,807
  • 7
  • 44
  • 74
  • I don't have access to any code now, but the [ScrollTo](http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.longlistselector.scrollto(v=vs.105).aspx) is not available? The LongListMultiSelector is an extension of the LongListSelector... – Depechie Jan 30 '13 at 14:32
  • No, it's not. Not on my machine at least. I have a standard Visual Studio Express 2012 installed. – src091 Jan 30 '13 at 14:39

1 Answers1

1

LongListSelector is kind of a "smart" controls. It means it has very complex behaviour but if you need to change it - better you shouldn't...

You have two options:

  1. Write your own behavior on top of the content of the LongListMultiSelector. It contains primitives:ScrollBox control inside it.
  2. Use standard LongListSelector and implement native ScrollTo method and your own multiselection. Multiselection is a simple task, ScrollTo is quite tricky since you basically can't scroll to position, only to item.
gleb.kudr
  • 1,518
  • 12
  • 16
  • Thanks, I'd rather go with first option if it can provide all the functionality I need (scrolling to an item rather than position is fine). How can I get to primitives:ScrollBox in LongListMultiSelector and where can I read about it? Google search only finds "ScrollBar" Class. – src091 Jan 30 '13 at 15:52
  • Also, under behavior do you mean C# custom behaviors as programming concept? – src091 Jan 30 '13 at 17:34
  • My mistake, it is primitives:ScrollBar. You can access it through LongListMultiSelector container as FrameworkElement by selecting a child with appropriate type http://stackoverflow.com/questions/636383/wpf-ways-to-find-controls Note than you can access it only when the list finished loading. Under behavior i mean simple your code to implement interaction, not c# concept. – gleb.kudr Jan 30 '13 at 20:02
  • BTW the first way may be more more complicated than the second. – gleb.kudr Jan 30 '13 at 20:15
  • 1
    Looks like I'll have to proceed with second option. Just tried a method from your link and `VisualTreeHelper.GetChildrenCount(parent)` returns 0. It's quite shocking actually that such an obvious funtionality is not included by default in `LongListMultiSelector`. – src091 Jan 30 '13 at 20:47
  • @Anton >VisualTreeHelper.GetChildrenCount(parent) returns 0. You shoud try to call this function inside Loaded event of LongListSelector. Otherwise it has not loaded yet and therefore has no child items. – gleb.kudr Jan 30 '13 at 22:20
  • Indeed you are right. It's working and I'm even able to reach to `LongListSelector` with it's `ScrollTo` function inside of `LongListMultiselector`. Still a lot is unclear but that's a topic for another question I guess. – src091 Jan 31 '13 at 11:42
  • @Anton you can write me on e-mail in the profile, I will give you some code for this task. Since I have already done this restore position task for my project. – gleb.kudr Jan 31 '13 at 15:53
  • Thanks a lot. I can't see any e-mail in your profile, mine is balshoy.tone@gmail.com – src091 Jan 31 '13 at 15:57