I’ve seen a few people asking this question. They have a page which contains a ListView and when an item is selected it navigates to another page. When they navigate backwards the ListView is back up to the top again. This behavior is due to the NavigationCacheMode of the page. By default the page will not cache rendered content when navigating “forward”. So when you navigate back to the page it re-renders the content. When displaying content like a ListView this will cause it to show the top content.

As with most things, there are a few solutions to this problem. The most common solution is to set the NaivationCacheMode to Enabled or Required.

public ListPage()
{
this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required;
}

These options do the following:

Member Value Description
Disabled 0

The page is never cached and a new instance of the page is created on each visit.

Required 1

The page is cached and the cached instance is reused for every visit regardless of the cache size for the frame.

Enabled 2

The page is cached, but the cached instance is discarded when the size of the cache for the frame is exceeded.

With this property set for the page the page content will not re-render because the rendered state has been cached!

It does get a little annoying to set the property for every page. I like to use a base page class that contains all my navigation stuff and cache mode as well. This makes it much easier to do the basic stuff.

public class AppPage : Page
{
public AppPage()
{
NavigationCacheMode = NavigationCacheMode.Enabled; // other stuff for navigation
}
} public partial class ListPage : AppPage
{
...
}

Unfortunately this is not a dependency property so you cannot create a base style that sets this property.

A second option is to use the ScrollIntoView method of the ListView. When your page loads, simply scroll your current item into view. This does have the drawback of not being at the exact same spot as before so I do recommend using the NavigationCacheMode.

查看原文

Why does my ListView scroll to the top when navigating backwards?的更多相关文章

  1. ListView数据更新后,自动滚动到底部(聊天时常用)| Listview Scroll to the end of the list after updating the list

    转:http://www.cnblogs.com/bjshsqlt/p/3311830.html If you would like to after you have updated by list ...

  2. Android listView scroll 恢复滚动位置

    相信大家尝试过许多方法恢复滚动位置,本人也找了许多方法,唯有这个方法好用,下面把代码贴出来 声明两个变量 private int mPosition; private int lvChildTop; ...

  3. offset / scroll / client Left / Top

    1.offsetHeight / Width (只读) offsetHeight:表示该元素在垂直方向占用的空间大小,包含元素的高度+上边框高度+下边框高度 offsetWidth:表示该元素在水平方 ...

  4. Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll

    Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...

  5. [Android实例] Scroll原理-附ScrollView源码分析

    想象一下你拿着放大镜贴很近的看一副巨大的清明上河图, 那放大镜里可以看到的内容是很有限的, 而随着放大镜的上下左右移动,就可以看到不同的内容了 android中手机屏幕就相当于这个放大镜, 而看到的内 ...

  6. Android用户界面 UI组件--AdapterView及其子类(一) ListView及各种Adapter详解

    ListView就是列表组件,一般通过继承ListActivity使用系统提供的ListView. 所有的AdapterView组件都需要有一个对应的Adapter作为适配器来显示列表中元素的布局方式 ...

  7. 下拉刷新,上拉装载许多其他ListView

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvanVuaHVhaG91c2U=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  8. [Android实例] Scroll原理-附ScrollView源码分析 (转载)

    想象一下你拿着放大镜贴很近的看一副巨大的清明上河图, 那放大镜里可以看到的内容是很有限的, 而随着放大镜的上下左右移动,就可以看到不同的内容了 android中手机屏幕就相当于这个放大镜, 而看到的内 ...

  9. wpf listview 换行

    <ListView  Name="listView1" VerticalAlignment="Top" Height="600" Ma ...

随机推荐

  1. FG函数模块

    ALDB:                             ABAP/4上的逻辑数据库                                   选择屏幕的修改更新 BUBA_4: ...

  2. Objective-C:Foundation框架-常用类-NSValue

    NSNumber是NSValue的子类,前者只能包装数字,后者可以包装任意值.NSArray.NSDictionary只能存储OC对象,不能存储结构体.因此,如果想要在NSArray.NSDictio ...

  3. js-分享107个js中的非常实用的小技巧(借鉴保存)

    转载原文:http://***/Show.aspx?id=285 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:doc ...

  4. JFrame面板

    1.可见性与透明性 可见性:当面板不可见时,则该面板中包含的组件会无法显示. 透明性:若该面板是可见且透明的,那么只是面板会透明(比如面板的背景色无法看到),面板上的组件仍会显示. 注:可见性通过se ...

  5. 10+优秀“分步引导”jQuery插件(转)

    很 多时候一个网站或者一个Web应用出品,为了让你的用户知道你的站点(或应用)有些什么?如何操作?为了让你的用户有更好的体验.往往这个时候都会给你的 站点(应用)添加一个分步指引的效果.然而这样的效果 ...

  6. vue.js——初体验

    看到最近很火的vue.js,于是开启了自己人生中首篇翻译之路,才意识到这个纯英文版的的确没有中文的通俗易懂~~~~~~不过, 还是硬着头皮把这篇英文版的博客给翻译完了,希望可以帮助自己的同时也方便别人 ...

  7. [转]连续创建多个Oracle触发器失败,单个创建才成功的解决方法

    连续创建多个Oracle触发器失败,单个创建才成功的解决方法   1.当我连续执行创建多个触发器时,总是报编译通过,但存在警告或错误.如下:   create or replace trigger t ...

  8. Java如何将控制台上的结果保存到文件

    无论是二进制数据还是字符数据(文本数据),都可以用文件输出流java.io.FileOutputStream,以字节流的方式保存到指定文件. package test; import java.io. ...

  9. PMP 项目管理

    1.什么是项目管理   项目管理就是把各种知识,技能,工具,技术应用于项目活动,来满足项目的需求.这个是从技术方面来说的.其实在项目管理的技术 层面背后,还有理念层面的内容.学习项目管理,除了学习技术 ...

  10. 创建论坛Discuz

    下载discuz! mkdir /data/wwwcd /data/wwwwget  http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GB ...