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"];
}
}