How to group items in a list by their first letter in Silverlight?

被刻印的时光 ゝ 提交于 2019-12-23 22:09:33

问题


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.

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


回答1:


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

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

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

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.

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




回答2:


You might find some inspiration in Erik Klimczak's implementation of a jump list control.




回答3:


A jump list is now available in the November release of the Windows Phone Toolkit.

Details here. Refer LongListSelector.

Mo controls, mo controls, mo controls... [Announcing the second release of the Silverlight for Windows Phone Toolkit!] - Delay's Blog




回答4:


I would use the SilverLight WP7 Toolkit's LongListSelector to do this. It can be confusing getting your head round how it works...I know I certainly did! So I have just put up a blog on how to create a nested Group suitable for this. However if you just a straight forward list with no group short-cut linking, then you can just bind to a normal collection and use as a straight list.

http://nicholasrogoff.wordpress.com/2011/01/28/creating-an-easy-grouped-observablecollection-for-the-longlistselector/



来源:https://stackoverflow.com/questions/3152540/how-to-group-items-in-a-list-by-their-first-letter-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!