开发者

Remembering Position of LongListSelector

I'm developing a Windows Phone 7 (WP7) app and I'm using a LongListSelector control for a list. When the user taps on one of the items, my event handler navigates to a new page for the selected item. However, when the user clicks on the back button to return to the previuos page, the LongListSelector is at a d开发者_如何学编程ifferent position than it was. Does anyone know how to remember the position of the selector and restore that position when it is returned to?


When you handle the SelectionChanged event, you can save the SelectedItem (which I assume you are already retrieving in order to determine the new page) to a page property. Then in the OnNavigatedTo event for the page, if that item is not null then 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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜