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. 20145236 《Java程序设计》实验二实验报告

    北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验日期:2016.04.08 实验名称: Java面向对象程序设计 实验内容: 初步掌握单元测试和T ...

  2. LSM树——放弃读能力换取写能力,将多次修改放在内存中形成有序树再统一写入磁盘

    LSM树(Log-Structured Merge Tree)存储引擎 代表数据库:nessDB.leveldb.hbase等 核心思想的核心就是放弃部分读能力,换取写入的最大化能力.LSM Tree ...

  3. BZOJ1590 [Usaco2008 Dec]Secret Message 秘密信息

    建立一颗trie树,记录下来每个点以它为结尾的字符串的个数cnt,和它的子树内有多少字符串size 于是查询的时候就只需要把沿途的cnt加起来,再加上最后的size就好了 /************* ...

  4. 如何解决链入js,innerHTML中文乱码问题呢?

    描述:发生在做suhuotong网站的时候,添加在线客服代码的时候三个地方1.将js以UTF-8无BOM编码:VS修改或者使用NotePad++修改2.<meta http-equiv=&quo ...

  5. Learn clojure in Y minutes

    Learn X in Y minutes Where X=clojure Get the code: learnclojure.clj Clojure is a Lisp family languag ...

  6. 什么是RAID

    RAID 维基百科,自由的百科全书 关于与「 RAID 」同名的其他主题,详见「 RAID (消歧义) 」. 独立硬盘冗余阵列 ( RAID , R edundant A rray of I ndep ...

  7. C#中三种定时器对象的比较

    ·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers ...

  8. plist文件的读取

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cinemalist" ofType:@"pl ...

  9. Oracle连接查询内容整理

    --内连接--select t.*,b.bumenmc from T_HQ_RYXX t,t_hq_bm b where t.bum = b.bumenbm--select * from t_hq_r ...

  10. 初步比较zeromq vs. wcf

    用最简单的Calculator比较zeromq的req-rep模式 vs. wcf的http和net.tcp模式,看哪一种的传输性能更高. 1.比较结果如下 方式 耗费时间 wcf_http_sing ...