如何在列表中按照他们在Silverlight中的第一个字母对项目进行分组? [英] How to group items in a list by their first letter in Silverlight?

查看:132
本文介绍了如何在列表中按照他们在Silverlight中的第一个字母对项目进行分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框,而我约束字符串的排序列表。我想以显示与该公布新的字母分隔(头)名单 - 像iPhone上的联系人列表中。

I have a ListBox to which I bound a sorted list of strings. I would like to display the list with dividers (headers) that announce the new letter - something like the 'Contacts' list on the iPhone.

是否有人知道如何实现这一目标?也许使用列表框是不正确的想法。

Does anybody know how to achieve this goal? Perhaps using ListBox is not the right idea.

我用VS 2010快做这行的Windows Phone 7。

I am doing this with VS Express 2010 for Windows Phone 7.

推荐答案

我不能为Silverlight的说话,但一般的.NET的做法是如下:

I can't speak for silverlight, but the general .NET Practice would be as follows:

var groupings = mySortedString.GroupBy(x => x.Substring(0,1));

这使得一个的IEnumerable< IGrouping<字符串,字符串>> 然后将绑定该列表到你的列表框。

This makes an IEnumerable<IGrouping<string, string>> you then would bind this list to your listbox.

从这里,你必须拿出XAML来表示它你怎么想,但是这组所有项目

From here you'd have to come up with the XAML to represent it how you'd like, but this would group all your items.

请注意: IGrouping<,> 工具的IEnumerable<方式> 所以你可以列举了它为它的项目

Note: IGrouping<,> implements IEnumerable<> so you can enumerate off it for it's items.

这篇关于如何在列表中按照他们在Silverlight中的第一个字母对项目进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆