[英]WP 8.1 Scroll to the top of the ListView
I would like to automatically scroll to the top of the ListView when the user navigates to this with the back button. 当用户使用后退按钮导航到ListView时,我想自动滚动到它的顶部。 I tried to use this:
我试图用这个:
scrollViewer.ScrollToVerticalOffset(0.0);
It works, but the VS says: 它可以工作,但是VS表示:
ScrollToVerticalOffset may be altered or unavailable for releases after Windows 8.1.
ScrollToVerticalOffset可能会更改或在Windows 8.1之后的版本中不可用。 Instead, use ChangeView.
而是使用ChangeView。
Okay, I thought it's no problem, I will use ChangeView instead of this. 好的,我认为这没问题,我将使用ChangeView代替它。 But the ChangeView doesn't work properly.
但是ChangeView无法正常工作。 At least in my case.
至少就我而言。 I tried this:
我尝试了这个:
scrollViewer.ChangeView(null, 0d, null);
It works when I call it for example from a button, but it doesn't do anything when I put it to the OnNavigatedTo method. 例如,当我从按钮调用它时,它可以工作,但是当我将其放入OnNavigatedTo方法时,它什么也没做。
So why does it work? 那为什么行得通呢?
If you take a look at MSDN description od OnNavigatedTo , you will see that it's called before the visual tree is loaded. 如果查看一下MSDN描述od OnNavigatedTo ,您会看到它在加载可视树之前被调用。 Therefore if you want to manipulate your UI elements - do it in Loaded event:
因此,如果要操作UI元素,请在Loaded事件中进行操作:
You cannot use OnNavigatedTo for element manipulation or state change of controls on the destination page.
您不能将OnNavigatedTo用于目标页面上的元素操作或控件的状态更改。 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.
相反,应在新加载的页面内容的根目录处附加一个Loaded事件处理程序,并在Loaded事件处理程序中执行任何元素操作,状态更改,事件接线等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.