Saving a LongListSelector Position

I am developing a Windows Phone 7 (WP7) application and I am using the LongListSelector control for a list. When the user clicks on one of the elements, my event handler jumps to a new page for the selected element. However, when the user clicks the back button to return to the previuos page, LongListSelector is in a different position than it was. Does anyone know how to remember a selector position and restore that position when it returns?

+4
source share
1 answer

When you handle the SelectionChanged event, you can save the SelectedItem (which I assume you already got to define a new page) for the page property. Then, in the OnNavigatedTo event for the page, if this element is not equal to zero, you can use the ScrollTo method. Something like this (where lls is your longlistselector):

 private object previousItem = null; private void lls_SelectionChanged(object sender, SelectionChangedEventArgs e) { object previousItem = lls.SelectedItem; //Page Navigation Magic } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (previousItem != null) lls.ScrollTo(previousItem); } 
+1
source

All Articles