Windows Phone 8.1 列表控件(3):多数据呈现
说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView。
而这两个控件实在太多东西可讲了,于是分成三篇来讲:
(3)多数据呈现
ListView 和 GridView 的最大差别就是:ListView 是一条条依序排列的,而 GridView 则是一块块依序排列的,因此 ListView 中的一项就会占据整整一行或者一列,而 GridView 的一项只会占据它应有的大小,一行或一列中可以放置多项。
而两者在其它方面上基本一致,因此下文只对 ListView 进行介绍,GridView 其实也一样的。
多数据呈现,也就是说大量的数据要在 ListView 中呈现时,加载必定会较慢,那要如何让用户体验更好呢?
(1)添加 ListView 的 ContainerContentChanging 事件
如字面意思所示,也就是当 ListView 的内容(也就是Item)发生改变时会触发的事件:
<ListView ContainerContentChanging="IncrementalUpdateHandler"/>
(2)确定 Item 内容的呈现顺序
比如 Item 的结构为:
Grid
|__Border name=templatePlaceholder
|__Image name=templateImage
|__Grid
|__TextBlock name=templateTitle
|__TextBlock name=templateSubTitle
一般的做法都是先让占位符(templatePlaceholder)呈现,然后根据每项内容的重要程度和加载难度依次排序呈现。
假设这个 Item 的呈现顺序为:Placeholder -> Title -> Image, SubTitle。
(3)处理 ListView 的 ContainerContentChanging 事件
private void IncrementalUpdateHandler(ListViewBase sender, ContainerContentChangingEventArgs args)
{
args.Handled = true; if( args.Phase != )
throw new Exception("something went terribly wrong");
else
{
Grid templateRoot = (Grid)args.ItemContainer.ContentTemplateRoot;
Border placeholder = (Border)templateRoot.FindName("templatePlaceholder");
Image itemImage = (Image)templateRoot.FindName("templateImage");
TextBlock title = (TextBlock)templateRoot.FindName("templateTitle");
TextBlock subtitle = (TextBlock)templateRoot.FindName("templateSubTitle"); placeholder.Opacity = ; itemImage.Opacity = ;
title.Opacity = ;
subtitle.Opacity = ; args.RegisterUpdateCallback(ShowText);
}
}
首先将 args.Handled 设为 true 以及检查 args.Phase 是否不为 0。
然后根据控件名称找到各控件,并根据需要设置每个控件的 Opacity,隐藏或显示它们。(注意,不能调整 Visible 属性,因为这会再次触发 ContainerContentChanging 事件)
最后调用 args.RegisterUpdateCallback(MethodName),显示下一个要呈现的控件内容。
private void ShowText(ListViewBase sender, ContainerContentChangingEventArgs args)
{
args.Handled = true; if( args.Phase != )
throw new Exception("something went terribly wrong");
else
{
SampleItem sItem = (SampleItem)args.Item; Grid templateRoot = (Grid)args.ItemContainer.ContentTemplateRoot;
TextBlock title = (TextBlock)templateRoot.FindName("templateTitle"); title.Text = sItem.Title;
title.Opacity = ;
args.RegisterUpdateCallback(ShowImage);
}
}
ShowText
private void ShowImage(ListViewBase sender, ContainerContentChangingEventArgs args)
{
args.Handled = true; if( args.Phase != )
throw new Exception("something went terribly wrong");
else
{
SampleItem sItem = (SampleItem)args.Item; Grid templateRoot = (Grid)args.ItemContainer.ContentTemplateRoot;
Image itemImage = (Image)templateRoot.FindName("templateImage");
TextBlock subtitle = (TextBlock)templateRoot.FindName("templateSubTitle");
Border placeholder = (Border)templateRoot.FindName("templatePlaceholder"); itemImage.Source = new BitmapImage(new Uri(sItem.ItemImage));
subtitle.Text = sItem.TargetGroup; itemImage.Opacity = ;
subtitle.Opacity = ; placeholder.Opacity = ;
}
}
ShowImage
其实也就是根据第二步中确定的内容呈现顺序依次调用 RegisterUpdateCallback。
Windows Phone 8.1 列表控件(3):多数据呈现的更多相关文章
- Windows Phone 8.1 列表控件(1):基本
说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView. 而这两个控件实在太多东西可讲了,于是分成三篇来讲: (1)基本 (2)分组数据 (3 ...
- Windows Phone 8.1 列表控件(2):分组数据
说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView. 而这两个控件实在太多东西可讲了,于是分成三篇来讲: (1)基本 (2)分组数据 (3 ...
- 《深入理解Windows Phone 8.1 UI控件编程》基于最新的Runtime框架
<深入理解Windows Phone 8.1 UI控件编程>本书基于最新的Windows Phone 8.1 Runtime SDK编写,全面深入地论述了最酷的UI编程技术:实现复杂炫酷的 ...
- 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView
原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...
- 重新想象 Windows 8 Store Apps (8) - 控件之 WebView
原文:重新想象 Windows 8 Store Apps (8) - 控件之 WebView [源码下载] 重新想象 Windows 8 Store Apps (8) - 控件之 WebView 作者 ...
- 重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter
原文:重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresente ...
- WPF: 实现带全选复选框的列表控件
本文将说明如何创建一个带全选复选框的列表控件.其效果如下图: 这个控件是由一个复选框(CheckBox)与一个 ListView 组合而成.它的操作逻辑: 当选中“全选”时,列表中所有的项目都 ...
- CListCtrlEx:一个支持文件拖放和实时监视的列表控件——用未公开API函数实现Shell实时监视
一.需求无论何时,当你在Explorer窗口中创建.删除或重命名一个文件夹/文件,或者插入拔除移动存储器时,Windows总是能非常快速地更新它所有的视图.有时候我们的程序中也需要这样的功能,以便当用 ...
- Windows常见窗口样式和控件风格
Windows常见窗口样式和控件风格 王佰营 徐丽红 一.窗口样式 WS_POPUP 弹出式窗口(不能与WS_CHILDWINDOW样式同时使用)WS_CHILDWINDOW 子窗口(不能与WS_PO ...
随机推荐
- android4.0蓝牙使能的详细解析
本文详细分析了android4.0 中蓝牙使能的过程,相比较android2.3,4.0中的蓝牙最大的差别在于UI上on/off的伪开关.在android4.0中加入了 adapter的状态机.所谓的 ...
- Java中Queue类实现
原先在java编程中,Queue的实现都是用LinkedList Queue queue = new LinkedList(); 但正如jdk中所说的那样: 注意,此实现不是同步的.如果多个线程同时访 ...
- 从user 登陆開始
首先.我们来看看我们的需求,看看需求里有没有你感兴趣的知识点: 用户登陆: 实现用户从网页登陆界面输入正确的username.password及验证码后跳转到一个页面显示登陆成功 要求: 1. 数据 ...
- Javascript-获取URL请求参数
function getUrlParam(){ var param = [], hash; var url = window.location.href;//获取网页的url va ...
- (转)Windows7 64位系统搭建Cocos2d-x 2.2.1最新版以及Android交叉编译环境(详细教程) .
声明:本教程在参考了以下博文,并经过自己的摸索后实际操作得出,本教程系本人原创,由于升级后的cocos2d-x有了一些变化,目前的博文还没有关于Cocos2d-x 2.2.1最新版搭建Android交 ...
- 关于 未能加载文件或程序集“MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或它的某一个依赖项。系统找不到指定的文件。
我这个项目是MVC4的,有两个版本,第一个版本直接运行没什么问题,但是跑第二个版本的时候就给我提示这个错误.好吧,百度果然是万能的.下边是解决方案. 1.找到 C:\Windows\Microsoft ...
- MapReduce中的作业调度
MapReduce是hadoop提供一个可进行分布式计算的框架或者平台,显然这个平台是多用户的,每个合法的用户可以向这个平台提交作业,那么这就带来一个问题,就是作业调度. 任何调度策略都考虑自己平台调 ...
- asp.net session容易丢失解决方案
web Form 网页是基于HTTP的,它们没有状态, 这意味着它们不知道所有的请求是否来自 同一台客户端计算机,网页是受到了破坏,以及是否得到了刷新,这样就可能造成信息的 丢失. 于是, 状态管理就 ...
- 命名管道FIFO
首先我得检讨一下自己,这几天有些颓呀,打不起精神,板子出了点问题,果真自学还是很困难呀,硬件方面难解决呀,理想与现实还是很有差距的,伤透了,凌乱了. 一直在理解进程间通信的问题.发现上次忽略了一个问题 ...
- 【技巧性(+递归运用)】UVa 1596 - Bug Hunt
In this problem, we consider a simple programming language that has only declarations of onedimensio ...