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的更多相关文章

  1. C#可扩展编程之MEF学习笔记(五):MEF高级进阶

    好久没有写博客了,今天抽空继续写MEF系列的文章.有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后. 前面四篇讲了MEF的基础知识,学完了前四篇,MEF中比较常用 ...

  2. (转)Qt Model/View 学习笔记 (五)——View 类

    Qt Model/View 学习笔记 (五) View 类 概念 在model/view架构中,view从model中获得数据项然后显示给用户.数据显示的方式不必与model提供的表示方式相同,可以与 ...

  3. java之jvm学习笔记五(实践写自己的类装载器)

    java之jvm学习笔记五(实践写自己的类装载器) 课程源码:http://download.csdn.net/detail/yfqnihao/4866501 前面第三和第四节我们一直在强调一句话,类 ...

  4. Learning ROS for Robotics Programming Second Edition学习笔记(五) indigo computer vision

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  5. Typescript 学习笔记五:类

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  6. ES6学习笔记<五> Module的操作——import、export、as

    import export 这两个家伙对应的就是es6自己的 module功能. 我们之前写的Javascript一直都没有模块化的体系,无法将一个庞大的js工程拆分成一个个功能相对独立但相互依赖的小 ...

  7. muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor

    目录 muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor Connector 系统函数connect 处理非阻塞connect的步骤: Connetor时序图 Accep ...

  8. python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍

    python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍 IDLE默认不能显示行号,使用ALT+G 跳到对应行号,在右下角有显示光标所在行.列.pycharm免费社区版.Su ...

  9. Go语言学习笔记五: 条件语句

    Go语言学习笔记五: 条件语句 if语句 if 布尔表达式 { /* 在布尔表达式为 true 时执行 */ } 竟然没有括号,和python很像.但是有大括号,与python又不一样. 例子: pa ...

  10. 【opencv学习笔记五】一个简单程序:图像读取与显示

    今天我们来学习一个最简单的程序,即从文件读取图像并且创建窗口显示该图像. 目录 [imread]图像读取 [namedWindow]创建window窗口 [imshow]图像显示 [imwrite]图 ...

随机推荐

  1. DNS 正向查找与反向查找

    原创地址:http://www.cnblogs.com/jfzhu/p/3996323.html 转载请注明出处 所谓正向查找,就是说在这个区域里的记录可以依据名称来查找对应的IP地址.反向查找就是在 ...

  2. C++虚函数表

    大家知道虚函数是通过一张虚函数表来实现的.在这个表中,主要是一个类的虚函数的地址表,这张表解决了继承.覆盖的问题,其内容真是反应实际的函数.这样,在有虚函数的类的实例中,这个表分配在了这个实例的内存中 ...

  3. IOS UIView 01-View开始深入 绘制像素到屏幕上

    注:本人是翻译过来,并且加上本人的一点见解. 前言 一个像素是如何绘制到屏幕上去的?有很多种方式将一些东西映射到显示屏上,他们需要调用不同的框架.许多功能和方法的结合体.这里我们大概的看一下屏幕之后发 ...

  4. 知方可补不足~SQL2008中的发布与订阅模式~续

    回到目录 上一回介绍了如何在sql2008中建立一个数据库的发布者,今天来说一下如何建立一个订阅者,其实订阅者也是一个数据库,而这个数据库是和发布者的数据结构相同的库,它们之间通过SQL代理进行数据上 ...

  5. 知方可补不足~SQL中的count命令的一些优化措施(百万以上数据明显)

    回到目录 SQL中对于求表记录总数的有count这个聚合命令,这个命令给我们感觉就是快,比一般的查询要快,但是,当你的数据表记录比较多时,如百万条,千万条时,对于count来说,就不是那么快了,我们需 ...

  6. EF架构~XMLRepository仓储的实现~续(XAttribute方式)

    回到目录 之前我写过关于XMLRepository仓储的实现的文章,主要是针对XElement方式的,对于XML的结构,一般来说有两种,一是使用节点方式的,我习惯称为XElement方式,别一种是属性 ...

  7. 使用JSSDK集成微信分享遇到的一些坑

    h5项目中需要集成微信分享,以实现自定义标题.描述.图片等功能.结果遇到了很多坑. 准备工作 务必详细阅读微信JS-SDK说明文档 需要后端支持 强烈建议下载使用微信web开发者工具 按文档配置好公众 ...

  8. fir.im Weekly - 17 个提升 iOS 开发效率的必备工具

    本期 fir.im Weekly 精选了一些iOS 开发工具和动画源码分享,希望每个开发者能专注效率.实用.灵感.  iOS开发工具--如何优化ipa包大小 @iOS程序犭袁 推荐了关于"如 ...

  9. MySQL5.7.13源代码阅读心得

    1.使用gdb这个调试工具. 在linux使用该调试工具非常简单.它的价值非常大,可以告诉你函数相互调用的逻辑(bt命令),告诉你函数执行的情况(通过br命令以及n,c命令单步跟踪函数每一个语句的执行 ...

  10. 让BI告诉你:圣诞老人去哪了?

    刚看到一篇关于圣诞节BI分析的文章,觉得很有意思,特来翻译了下和大家一起分享(可惜的是文章发布的时间有点久). 伴随着圣诞节即将到来的日子,POWER BI团队来回答大家最为关注的一个问题:圣诞老人到 ...