说到 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。

最新文章

  1. Qt 环境下的mapx控件-------2
  2. QT屏蔽qDebug的方法
  3. 转:Web前端,高性能优化
  4. XAF应用开发教程(二)业务对象模型之简单类型属性
  5. ARM汇编常用指令
  6. Android——开发环境
  7. hdu 1515 Anagrams by Stack
  8. -_-#【CSS3】浏览器前缀
  9. leetcode回文子串拆分-最小拆分次数
  10. 机器学习系统设计(Building Machine Learning Systems with Python)- Willi Richert Luis Pedro Coelho
  11. Linux运维基础
  12. 浅析AnyCast网络技术
  13. TensorFlow学习笔记(1):variable与get_variable, name_scope()和variable_scope()
  14. NaviCat SqlServer Windows 10 Update 1803 IM004 - Driver&#39;s SQLAllocHandle on SQL_HANDLE_ENV failed
  15. 另辟蹊径 直取通州的“墨迹天气”APP应用的成功故事
  16. C++将一个vector中的内容复制到另一个vector结尾
  17. 15 Puzzle (4乘4谜题) IDA*(DFS策略与曼哈顿距离启发) 的C语言实现
  18. Objective-C函数重载规则
  19. WarTransportation TopCoder - 8404
  20. SpringCloud的学习记录(7)

热门文章

  1. iOS开发——实用篇&amp;KVO与KVC详解
  2. 高级I/O之readn和writen函数
  3. debian下软件包管理方式总结
  4. c语言中文件的操作
  5. c# TCP/IP编程
  6. Android(java)学习笔记106-2:反射机制
  7. Python mongoDB 的简单操作
  8. 【gradle报错】error: package org.apache.http does not exist
  9. Python基础复习_Unit one
  10. wince 位图的使用