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. 解决Win7 软件图标不显示--Win7图标异常,快捷方式不显示解决方法

    电脑症状:WIN7的系统,桌面上的图标显示的不正常,快捷方式显示的是未知程序.看不到程序默认图标,快捷方式图标不显示. 解决方法:删除程序图标缓存即可.   将下面的内容复制到记事本保存为“Repai ...

  2. 页面动态加入<script>标签并执行代码

    在页面中动态追加html片段的时候,有时候动态添加的代码会含有<script>标签,比如用了一些模板引擎,或者你的代码有些复杂的时候.然而我们用DOM提供的innerHTML方式来添加代码 ...

  3. [蓝牙] 2、蓝牙BLE协议及架构浅析&&基于广播超时待机说广播事件

    第一章 BLE基本概念了解 一.蓝牙4.0和BLE区别   蓝牙4.0是一种应用非常广泛.基于2.4G射频的低功耗无线通讯技术.蓝牙低功耗(Bluetooth Low Energy ),人们又常称之为 ...

  4. Python中的几种数据类型

    大体上把Python中的数据类型分为如下几类:   Number(数字) 包括int,long,float,complex String(字符串) 例如:hello,"hello" ...

  5. 在github上写个人简历——先弄个主页

    起因 不知道园友们在使用智联招聘等网站填写简历的时候对要求输入的内容有没有一种无力感,不吐槽了反正就一句话,按照它提供的格式我没法儿写简历,而且面试的时候总会被问道有没有自己作品,哥们儿天天上班,下班 ...

  6. easy-ui 小白进阶史(二):操作数据,easy-ui操作

    easy-ui的操作及交互: Html: @using LangBo.Facade; @using LangBo.DataDefine; @using System.Threading.Tasks; ...

  7. java 堆栈分析4

    jprofiler ,又是一款好工具... —— 不过显然,我觉得有了jvisualvm就足够了,难道它会比jvisualvm还强大很多!?? 什么时候需要它呢?它有什么特别好用的地方吗? 带来什么方 ...

  8. js笔记——call,apply,bind使用笔记

    call和apply obj.call(thisObj, arg1, arg2, ...); obj.apply(thisObj, [arg1, arg2, ...]); 两者作用一致,都是把obj( ...

  9. MyBatis学习总结(一)——MyBatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  10. Hidden File For Mac

    显示所有隐藏文件的方法: terminal中输入: defaults write com.apple.finder AppleShowAllFiles -bool true 同理,再次隐藏就输入: d ...