WinPhone学习笔记(五)——LongListSelector
LongListSelector也是WinPhone的特色控件之一,最初不了解这个控件叫啥名,知道它会在"人脉"里面出现,在应用程序列表也是这个LongListSelector(如果应用的数量多的话就会出现分组的标头),"音乐"里面的曲目使用了这个控件;其他非系统的应用也有使用这个LongListSelector:酷我音乐、微信、飞信、微博……


这个列表的快速跳转方式和Android的联系人侧边索引栏作用比较相似,从界面美观程度来说LongListSelector没那么好,但是从操作性来说LongListSelector就比较好了,容易被点击中。

这个LongListSelector在WP8的模板中存在于工具箱的"常用的Windows Phone控件"一栏中,在页面中添加LongListSelector控件
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector
x:Name="AddrBook"/>
</Grid>
添加了控件,那要介绍一下LongListSelector的组成


如上图所示,一个LongListSelector有列表的表头(ListHeaderTemplate)、表尾(ListFooterTemplate)、组头(GroupHeaderTemplate)、组尾(GroupFooterTemplate)
鄙人对WPF没有系统地去了解,实践这个LongListSelector过程中让我了解到静态资源和依赖属性,上图右边的那个效果,xmal代码如下
<phone:LongListSelector
x:Name="AddrBook"
JumpListStyle="{StaticResource AddrBookJumpListStyle}"
Background="Transparent"
GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"
GroupFooterTemplate="{StaticResource AddrBookGroupFooterTemplate}"
ItemTemplate="{StaticResource AddrBookItemTemplate}"
LayoutMode="List"
IsGroupingEnabled="true"
HideEmptyGroups ="true"/>
这里用到了三个Template一个Style,都是静态资源,它们的定义如下
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="AddrBookItemTemplate">
<StackPanel VerticalAlignment="Top">
<TextBlock Text="{Binding FirstName}"
FontSize="40"
local:MetroInMotion.AnimationLevel="3"
local2:TiltEffect.IsTiltEnabled="True"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="AddrBookGroupFooterTemplate">
<Border Background="{StaticResource PhoneAccentBrush}"
BorderBrush="{StaticResource PhoneAccentBrush}"
BorderThickness="2"
Width="62"
Height="62"
Margin="0,0,18,0"
VerticalAlignment="Center"
HorizontalAlignment="Left">
<TextBlock
Text="{Binding Key}"
Foreground="{StaticResource PhoneForegroundBrush}"
FontSize="48"
Padding="6"/> </Border>
</DataTemplate>
<DataTemplate x:Key="AddrBookGroupHeaderTemplate">
<Border Background="Transparent" Padding="5">
<Border Background="Transparent"
BorderBrush="{StaticResource PhoneAccentBrush}"
BorderThickness="2"
Width="Auto"
Height="62"
Margin="0,0,18,0"
HorizontalAlignment="Left">
<TextBlock Text="{Binding ChineseKey}"
Foreground="{StaticResource PhoneAccentBrush}"
FontSize="48"
Padding="6"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Border>
</Border>
</DataTemplate>
<phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/>
<phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/> <Style x:Key="AddrBookJumpListStyle" TargetType="phone:LongListSelector">
<Setter Property="GridCellSize" Value="200,113"/>
<Setter Property="LayoutMode" Value="Grid"/>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="{Binding Converter={StaticResource BackgroundConverter}}"
Width="Auto" Height="113" Margin="6" >
<TextBlock Text="{Binding ChineseKey}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
FontSize="48" Padding="6"
Foreground="{Binding Converter={StaticResource ForegroundConverter}}"
VerticalAlignment="Center"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
这里面就包含了三个Template一个Style,AddrBookItemTemplate的Template是组内各个Item的布局,AddrBookGroupFooterTemplate、AddrBookGroupHeaderTemplate,AddrBookJumpListStyle。
- AddrBookItemTemplate里面就一个TextBlock,它的Text属性则绑定了数据源中的Key属性。
- AddrBookGroupFooterTemplate则是一个主体色的62*62的矩形里面放一个TextBlock,TextBlock的Text也是绑定了数据源的Key属性。
这里用到的Temple和Style,让我想起了在Android里面用到的ListView,GridView里面等集合控件,这两个控件都需要用子项的布局文件,通过Adapter和ListView、GridView等空间关联起来,而在WinPhone就用
ItemTemplate="{StaticResource AddrBookItemTemplate}"
<DataTemplate x:Key="AddrBookItemTemplate">
<StackPanel VerticalAlignment="Top">
<TextBlock Text="{Binding FirstName}"
FontSize="40" />
</StackPanel>
</DataTemplate>
定义各个部分之间的布局。
这个LongListSelector所用的数据源的数据结构不是单纯的一个列表,它实际上是一个List<List<T>>,但特殊之处是他List<T>里面有分组用的属性。如下面的类
public class AlphaKeyGroup<T> : List<T>
{ /// <summary>
/// The Key of this group.
/// </summary>
public string Key { get; private set; } public string ChineseKey { get; private set; } /// <summary>
/// Public constructor.
/// </summary>
/// <param name="key">The key for this group.</param>
public AlphaKeyGroup(string key)
{
Key = key;
}
}
类中的Key和ChineseKey都可以是作为分组的Key,按照微软的例子这个类还会有两个方法专门处理分组,要弄这个分组用的方法多种多样,如果直接构造的话可以写成这样
List<AlphaKeyGroup<AddressBook>> result = new List<AlphaKeyGroup<AddressBook>>();
result.Add(new AlphaKeyGroup<AddressBook>("分组1")
{
new AddressBook("Joe", "Smith", "US", ""),
new AddressBook("Jim", "Johnson", "UK", ""),
new AddressBook("Mary", "Robert", "India", ""),
new AddressBook("Patricia", "James", "France", ""),
new AddressBook("Linda", "Williams", "Italy", ""),
new AddressBook("David", "Jones", "US", ""),
new AddressBook("Elizabeth", "Martinez", "US", ""),
new AddressBook("Richard", "Robinson", "Germany", ""),
new AddressBook("Charles", "Clark", "US", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组2")
{
new AddressBook("Laura", "Crawford", "US", ""),
new AddressBook("Anthony", "Burns", "US", ""),
new AddressBook("Sarah", "Gordon", "India", ""),
new AddressBook("Kevin", "Hunter", "US", ""),
new AddressBook("Kimberly", "Tucker", "US", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组3")
{
new AddressBook("Paul", "Hernandez", "US", ""),
new AddressBook("Karen", "King", "US", ""),
new AddressBook("Ruth", "Wright", "US", ""),
new AddressBook("Steven", "Lopez", "US", ""),
new AddressBook("Edward", "Hill", "US", ""),
new AddressBook("Sharon", "Scott", "US", ""),
new AddressBook("Brian", "Green", "US", ""),
new AddressBook("Michelle", "Ramos", "US", ""),
new AddressBook("Ronald", "Mason", "India", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组4")
{
new AddressBook("Joseph", "Rodriguez", "France", ""),
new AddressBook("Susan", "Lewis", "Italy", ""),
new AddressBook("Thomas", "Lee", "US", ""),
new AddressBook("Margaret", "Walker", "US", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组5")
{
new AddressBook("Deborah", "Mills", "US", ""),
new AddressBook("Matthew", "Warren", "US", ""),
new AddressBook("Jessica", "Nichols", "US", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组6")
{
new AddressBook("Christopher", "Hall", "UK", ""),
new AddressBook("Lisa", "Allen", "US", ""),
new AddressBook("Daniel", "Young", "US", ""),
});
result.Add(new AlphaKeyGroup<AddressBook>("分组7")
{
new AddressBook("Jason", "Dixon", "US", ""),
new AddressBook("Gary", "Knight", "US", ""),
new AddressBook("Shirley", "Ferguson", "US", ""),
});
WinPhone学习笔记(五)——LongListSelector的更多相关文章
- C#可扩展编程之MEF学习笔记(五):MEF高级进阶
好久没有写博客了,今天抽空继续写MEF系列的文章.有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后. 前面四篇讲了MEF的基础知识,学完了前四篇,MEF中比较常用 ...
- (转)Qt Model/View 学习笔记 (五)——View 类
Qt Model/View 学习笔记 (五) View 类 概念 在model/view架构中,view从model中获得数据项然后显示给用户.数据显示的方式不必与model提供的表示方式相同,可以与 ...
- java之jvm学习笔记五(实践写自己的类装载器)
java之jvm学习笔记五(实践写自己的类装载器) 课程源码:http://download.csdn.net/detail/yfqnihao/4866501 前面第三和第四节我们一直在强调一句话,类 ...
- Learning ROS for Robotics Programming Second Edition学习笔记(五) indigo computer vision
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...
- Typescript 学习笔记五:类
中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...
- ES6学习笔记<五> Module的操作——import、export、as
import export 这两个家伙对应的就是es6自己的 module功能. 我们之前写的Javascript一直都没有模块化的体系,无法将一个庞大的js工程拆分成一个个功能相对独立但相互依赖的小 ...
- muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor
目录 muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor Connector 系统函数connect 处理非阻塞connect的步骤: Connetor时序图 Accep ...
- python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍
python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍 IDLE默认不能显示行号,使用ALT+G 跳到对应行号,在右下角有显示光标所在行.列.pycharm免费社区版.Su ...
- Go语言学习笔记五: 条件语句
Go语言学习笔记五: 条件语句 if语句 if 布尔表达式 { /* 在布尔表达式为 true 时执行 */ } 竟然没有括号,和python很像.但是有大括号,与python又不一样. 例子: pa ...
- 【opencv学习笔记五】一个简单程序:图像读取与显示
今天我们来学习一个最简单的程序,即从文件读取图像并且创建窗口显示该图像. 目录 [imread]图像读取 [namedWindow]创建window窗口 [imshow]图像显示 [imwrite]图 ...
随机推荐
- 支持断点续传的文件上传插件——Huploadify-V2.0来了
之前仿造uploadify写了一个HTML5版的文件上传插件,没看过的朋友可以点此先看一下~得到了不少朋友的好评,我自己也用在了项目中,不论是用户头像上传,还是各种媒体文件的上传,以及各种个性的业务需 ...
- 相识Highcharts,几分钟玩转Highcharts
Highcharts是一个功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库. 官网:http://www.hcharts.cn/ 我觉得对于刚接触一个东西的新手来说,有时候对一个东西真 ...
- [转]quick-cocos2d-x 多分辨率适配详解
http://cn.quick-x.com/?p=1436 多种分辨率的适配一直都是一个蛋疼的问题,各家公司可能都有自己的一套方案.今天我为大家介绍的是我们在多款游戏里实践后的解决方案,相对来说成本和 ...
- JVM内存回收机制简述
JVM内存回收机制涉及的知识点太多了,了解越多越迷糊,汗一个,这里仅简单做个笔记,主要参考<深入理解Java虚拟机:JVM高级特性与最佳实践(第二版)> 目前java的jdk默认虚拟机为H ...
- 当pageIndex遇上pageNo
我们的项目程序里,由于赶项目进度,同时,大家缺乏相应的沟通,在服务层提供的接口里,涉及到分页查询的,有如下三种情形: l List<OrderInfo> GetOrderList(Ord ...
- 我心中的核心组件(可插拔的AOP)~调度组件quartz.net
回到目录 quartz.net是一个任务调度组件,它可以灵活的设置你的调试方式,按时间,按日期,按周期都可以很容易的实现,quartz不仅可以用在web中,而且还可以部署在winform,winser ...
- MVVM架构~knockoutjs系列之验证成功提示显示
返回目录 对于knockout.validation来说,我们已经知道了如何去验证大部分表单元素,而有时,我们的需求希望在每个元素验证成功后,去显示正确的提示,这个我们很容易的使用self.元素.is ...
- PHP面向对象06_异常处理
oop06异常处理 2014-9-2 8:36:33 NotePad++ By jiancaigege 摘要: 1.异常处理 2.类中常用函数 异常处理 语法格式: try{ //捕获异常 }catc ...
- Atitit vod click event design flow 视频点播系统点击事件文档
Atitit vod click event design flow 视频点播系统点击事件文档 重构规划1 Click cate1 Click mov4 重构规划 事件注册,与事件分发管理器分开 ...
- Atititcmd cli环境变量的调用设置与使用
Atititcmd cli环境变量的调用设置与使用 1.1. Cgi 环境变量的调用设置与使用1 1.2. 环境变量vs 系统变量1 1.3. 环境变量的分类 A.与服务器相关的环境变量B ,与客户 ...