说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView。

而这两个控件实在太多东西可讲了,于是分成三篇来讲:

(1)基本

(2)分组数据

(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):多数据呈现的更多相关文章

  1. Windows Phone 8.1 列表控件(1):基本

    说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView. 而这两个控件实在太多东西可讲了,于是分成三篇来讲: (1)基本 (2)分组数据 (3 ...

  2. Windows Phone 8.1 列表控件(2):分组数据

    说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView. 而这两个控件实在太多东西可讲了,于是分成三篇来讲: (1)基本 (2)分组数据 (3 ...

  3. 《深入理解Windows Phone 8.1 UI控件编程》基于最新的Runtime框架

    <深入理解Windows Phone 8.1 UI控件编程>本书基于最新的Windows Phone 8.1 Runtime SDK编写,全面深入地论述了最酷的UI编程技术:实现复杂炫酷的 ...

  4. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

  5. 重新想象 Windows 8 Store Apps (8) - 控件之 WebView

    原文:重新想象 Windows 8 Store Apps (8) - 控件之 WebView [源码下载] 重新想象 Windows 8 Store Apps (8) - 控件之 WebView 作者 ...

  6. 重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter

    原文:重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresente ...

  7. WPF: 实现带全选复选框的列表控件

    本文将说明如何创建一个带全选复选框的列表控件.其效果如下图:     这个控件是由一个复选框(CheckBox)与一个 ListView 组合而成.它的操作逻辑: 当选中“全选”时,列表中所有的项目都 ...

  8. CListCtrlEx:一个支持文件拖放和实时监视的列表控件——用未公开API函数实现Shell实时监视

    一.需求无论何时,当你在Explorer窗口中创建.删除或重命名一个文件夹/文件,或者插入拔除移动存储器时,Windows总是能非常快速地更新它所有的视图.有时候我们的程序中也需要这样的功能,以便当用 ...

  9. Windows常见窗口样式和控件风格

    Windows常见窗口样式和控件风格 王佰营 徐丽红 一.窗口样式 WS_POPUP 弹出式窗口(不能与WS_CHILDWINDOW样式同时使用)WS_CHILDWINDOW 子窗口(不能与WS_PO ...

随机推荐

  1. 浅谈Java对象回收的三种方式

    半夜睡不着,加上最近在看Java虚拟机,写点给新手和自己看的东西. 第一类:生命周期中止 void scope(){ Test t = new Test(); } 第二类:对象无引用 (一).对象的应 ...

  2. 教你使用Android SDK布局优化工具layoutopt

    创建好看的Android布局是个不小的挑战,当你花了数小时调整好它们适应多种设备后,你通常不想再重新调整,但笨重的嵌套布局效率往往非常低下,幸运的是,在Android SDK中有一个工具可以帮助你优化 ...

  3. android短信的接收和发送处理

    一 初始化 手机开机初始化调用GSMPhone 构造函数. GSMPhone (Context context, CommandsInterface ci, PhoneNotifier notifie ...

  4. [AngularJS] Build Your Own ng-controller Directive

    /** * Created by Answer1215 on 12/21/2014. */ angular.module('app', []) .controller('FirstCtrl' , fu ...

  5. 步进循环语句for

    一.for语句的基本格式 for 变量 in 列表 do 语句块 done 二.使用for语句处理列表(数组) [root@localhost shell]# cat use_for_deal_wit ...

  6. css 之position用法详解

    css  之position用法详解: http://www.jb51.net/web/77495.html

  7. BootStrap2学习日记9---文本框的前缀和后缀

    先来看一段代码: <form method="" action=""> <div class="input-append input ...

  8. Android(java)学习笔记91:泛型接口的概述和使用

    package cn.itcast_06; /* * 泛型接口:把泛型定义在接口上 */ public interface Inter<T> { public abstract void ...

  9. iOS XMPP(2)自己创建客户端

    一.目的以及效果: 用Xcode利用xmpp框架建立客户端,实现向服务器注册添加用户 密码,以及登陆,离线状态 工程的主要结构:新建singleview工程,用xib拖放两个输入框和两个按钮, 并在v ...

  10. EXTJS 常用控件的使用

    重要按钮配置项 handler: renderTo: 取得控件及其值 var memo = form.findById('memo');//取得输入控件 alert(memo.getValue()); ...