WP 8.1 滚动到 ListView 的顶部
WP 8.1 Scroll to the top of the ListView
我想在用户使用后退按钮导航到 ListView 时自动滚动到顶部。我试着用这个:
scrollViewer.ScrollToVerticalOffset(0.0);
有效,但 VS 显示:
ScrollToVerticalOffset may be altered or unavailable for releases
after Windows 8.1. Instead, use ChangeView.
好吧,我觉得没问题,我就用ChangeView代替这个。但是 ChangeView 不能正常工作。至少在我的情况下。我试过这个:
scrollViewer.ChangeView(null, 0d, null);
当我从一个按钮调用它时它起作用,但是当我将它放入 OnNavigatedTo 方法时它不做任何事情。
那么它为什么有效?
如果你看一下at MSDN description od OnNavigatedTo, you will see that it's called before the visual tree is loaded. Therefore if you want to manipulate your UI elements - do it in Loaded事件:
You cannot use OnNavigatedTo for element manipulation or state change of controls on the destination page. Instead, attach a Loaded event handler at the root of the newly loaded page's content, and perform any element manipulations, state changes, event wiring and so on in the Loaded event handler.
我想在用户使用后退按钮导航到 ListView 时自动滚动到顶部。我试着用这个:
scrollViewer.ScrollToVerticalOffset(0.0);
有效,但 VS 显示:
ScrollToVerticalOffset may be altered or unavailable for releases after Windows 8.1. Instead, use ChangeView.
好吧,我觉得没问题,我就用ChangeView代替这个。但是 ChangeView 不能正常工作。至少在我的情况下。我试过这个:
scrollViewer.ChangeView(null, 0d, null);
当我从一个按钮调用它时它起作用,但是当我将它放入 OnNavigatedTo 方法时它不做任何事情。
那么它为什么有效?
如果你看一下at MSDN description od OnNavigatedTo, you will see that it's called before the visual tree is loaded. Therefore if you want to manipulate your UI elements - do it in Loaded事件:
You cannot use OnNavigatedTo for element manipulation or state change of controls on the destination page. Instead, attach a Loaded event handler at the root of the newly loaded page's content, and perform any element manipulations, state changes, event wiring and so on in the Loaded event handler.