Windows Phone 7 Tip (6) -- 如何恢复离开页面时的list位置

不废话,上代码:)

 

代码
private double? scrollOffset;

private void scrollViewerHome_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (scrollOffset.HasValue)
{
scrollViewerHome.ScrollToVerticalOffset(scrollOffset.Value);
scrollOffset
= null; // No need to set the scroll offset again
}
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
State[
"ScrollOffsetKey"] = scrollViewerHome.VerticalOffset;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{

if (State.ContainsKey("ScrollOffsetKey"))
{
scrollOffset
= (double)State["ScrollOffsetKey"];
}
}

 

posted @ 2010-07-26 19:14  上尉  阅读(261)  评论(1编辑  收藏  举报
View Hao Wang's profile on LinkedIn