Why does my ListView scroll to the top when navigating backwards?
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?的更多相关文章
- 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 ...
- Android listView scroll 恢复滚动位置
相信大家尝试过许多方法恢复滚动位置,本人也找了许多方法,唯有这个方法好用,下面把代码贴出来 声明两个变量 private int mPosition; private int lvChildTop; ...
- offset / scroll / client Left / Top
1.offsetHeight / Width (只读) offsetHeight:表示该元素在垂直方向占用的空间大小,包含元素的高度+上边框高度+下边框高度 offsetWidth:表示该元素在水平方 ...
- 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 ...
- [Android实例] Scroll原理-附ScrollView源码分析
想象一下你拿着放大镜贴很近的看一副巨大的清明上河图, 那放大镜里可以看到的内容是很有限的, 而随着放大镜的上下左右移动,就可以看到不同的内容了 android中手机屏幕就相当于这个放大镜, 而看到的内 ...
- Android用户界面 UI组件--AdapterView及其子类(一) ListView及各种Adapter详解
ListView就是列表组件,一般通过继承ListActivity使用系统提供的ListView. 所有的AdapterView组件都需要有一个对应的Adapter作为适配器来显示列表中元素的布局方式 ...
- 下拉刷新,上拉装载许多其他ListView
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvanVuaHVhaG91c2U=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- [Android实例] Scroll原理-附ScrollView源码分析 (转载)
想象一下你拿着放大镜贴很近的看一副巨大的清明上河图, 那放大镜里可以看到的内容是很有限的, 而随着放大镜的上下左右移动,就可以看到不同的内容了 android中手机屏幕就相当于这个放大镜, 而看到的内 ...
- wpf listview 换行
<ListView Name="listView1" VerticalAlignment="Top" Height="600" Ma ...
随机推荐
- Struts2 用 s:if test 判断String类型的对象属性值和单字符是否相等的问题
Struts2 用 s:if test 判断String类型的对象属性值和单字符是否相等的问题 首先,这里所指的单字符形如:Y,男. 有两种做法: a. <s:if test='news.s ...
- MySql与SqlServer的一些常用用法的差别
MySql与SqlServer的一些常用用法的差别 本文为转载 本文将主要列出MySql与SqlServer不同的地方,且以常用的存储过程的相关内容为主. 1. 标识符限定符 SqlServer [] ...
- SAP采购订单审批记录增强
采购订单审核函数: BAPI_PO_RELEASE 结尾加上 ENHANCEMENT ZME28_PO. "active version DATA:LS_EKKO TYPE EKKO. DA ...
- AES加密 16进制与二进制转换
import java.security.Key; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax ...
- Excel VBA记录
-----------快捷键---------- 函数等提示(默认):ctrl+j 注释:上单引号' 设置单元格为空可以用:empty/null -----------基础语法--------- 基本 ...
- C#Base64编码
一. Base64的编码规则 Base64编码的思想是是采用64个基本的ASCII码字符对数据进行重新编码.它将需要编码的数据拆分成字节数组.以3个字节为一组.按顺序排列24 位数据,再把这24位数据 ...
- IE7的overflow失效的解决方法
IE7的position:relative bug今天遇到了一个相对定位(position:relaitve)引起的IE7中overflow:hidden失效的bug,特此记录!解决方法很简单,给父层 ...
- 银行支票和汇票中使用的专用字体MICR E13B条形码控件字体
MICR E13B条形码控件字体是一种在美国.加拿大.波多黎各.巴拿马.英国和其它少数国家的银行支票和汇票中使用的专用字体,主要用来打印适用于磁性和光学字符识别系统的MICR字符.MICR E13B条 ...
- checkbox的全选、反选、删除(适配器)
package com.example.adapter; import java.util.List; import com.example.ay.R;import com.example.vo.Fl ...
- SharePoint 2013 重复的管理账户错误:已添加项。字典中的关键字 所添加的关键字
博客地址:http://blog.csdn.net/FoxDave 今天在管理中心创建新的Web应用程序时,想注册一个新的管理账户,一着急点了两次按钮,结果就出现了这样的错误...怎么说呢,太奇葩 ...